`with` across function calls

luckoverthere luckoverthere at gmail.cm
Fri Jan 18 23:10:12 UTC 2019


On Friday, 18 January 2019 at 12:35:33 UTC, Nicholas Wilson wrote:
> q.enqueue!(f!(args))(arg_set1)(arg_set2);
>
> and the function within that needs `g` also needs `f`. The 
> expected usage is a whole lot of those calls all in one spot 
> with different `f`, `args`, `arg_set1`, `arg_set2` I really 
> don't want the user to have to repeat themselves anymore than 
> absolutely necessary.

Isn't that the usual argument between using globals and not using 
them. It's a lot cleaner when using them, especially when it is 
some sort of data that needs to be passed to basically 
everything. But then you deal with the joys of globals.

The use case for this is very narrow and the implementation is 
error prone. Having to go through and check functions to see 
which one's have altered behavior in a with statement isn't going 
to be fun. In the general case this doesn't make any sense, eg I 
don't see this being used anywhere in phobos at all. It'd be the 
very specific case of an API that needs to pass around some sort 
of state-like object a bunch of functions.

The rationale is also pretty weak, you want reduce the number of 
arguments you have to pass in this one specific use case. 
Honestly from the looks of that function call, it might be better 
just finding a better way of implementing whatever it is you are 
trying to implement.


More information about the Digitalmars-d mailing list