Re: Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Feb 12, 2022 at 05:52:01PM +, 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

-- 
Век живи - век учись. А дураком помрёшь.


Re: Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread Basile B. via Digitalmars-d-learn

On Saturday, 12 February 2022 at 12:36:06 UTC, BoQsc wrote:

`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?


Here is an ugly solution, just to encourage someone else to post 
better:


```d
enum n = "i+1The problem of the initial problem is to have automatic capture 
of `i` and `args` in any scope...


Lost cause ?


Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread BoQsc via Digitalmars-d-learn

`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?