bool nextArgumentDoesNotReachEndOfArray = i + 1 < args.length;
How can I declare it out of scope and reuse it in any scope that has i
and args.length
declared?
Thread overview | |||||
---|---|---|---|---|---|
|
February 12, 2022 Declaring a reusable formula and using it in other scopes. | ||||
---|---|---|---|---|
| ||||
How can I declare it out of scope and reuse it in any scope that has |
February 12, 2022 Re: Declaring a reusable formula and using it in other scopes. | ||||
---|---|---|---|---|
| ||||
Posted in reply to BoQsc | On Saturday, 12 February 2022 at 12:36:06 UTC, BoQsc wrote: >
How can I declare it out of scope and reuse it in any scope that has Here is an ugly solution, just to encourage someone else to post better:
The problem with that solution is that it's not clean. Lost cause ? |
February 12, 2022 Re: Declaring a reusable formula and using it in other scopes. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Sat, Feb 12, 2022 at 05:52:01PM +0000, Basile B. via Digitalmars-d-learn wrote: [...] > The problem with that solution is that it's not clean. > The problem of the initial problem is to have automatic capture of `i` > and `args` in any scope... > > Lost cause ? Lost cause, IMO. Automatic capture of arbitrary identifiers, while it seems useful at first glance, leads to all sorts of problems down the road. Consider, for example, what happens if a typo made it capture something in an outer or global scope, for example. Or if `i` and `args` happen to be defined with the wrong types. Or if somebody modified the mixin to capture something *other* than what you expected it to capture (i.e., encapsulation breakage). If you work through these unwanted cases, you eventually have to conclude that explicitly passing them as arguments is globally superior, in spite of being locally more inconvenient. T -- Век живи - век учись. А дураком помрёшь. |