`with` across function calls

Nicholas Wilson iamthewilsonator at hotmail.com
Sat Jan 19 00:23:40 UTC 2019


On Friday, 18 January 2019 at 23:10:12 UTC, luckoverthere wrote:
> 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.

How do you know? I don't think it would be all that much more 
complex than default arguments.

> 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.

grep?  ^f? Also again, this isn't any worse than default 
arguments.

> In the general case this doesn't make any sense,

That is a bold claim: have a watch of Martin's keynote.

> eg I don't see this being used anywhere in phobos at all.

Of course not, phobos doesn't deal in contexts (except maybe 
std.concurrency / std.parallelism, IDK, I haven't looked at their 
implementation). That doesn't mean that lots of other code 
doesn't.

> 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.

The case of dealing with contexts is hardly unique to me.

> 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.

Its globals or this, and I'd rather not use globals. More 
specifically, in

q.enqueue!(f!(args))(arg_set1)(arg_set2);

arg_set1 is the shape of the kernel dispatch and (if `q` is an 
out of order Queue) the dependency list of enqueue and other 
things that need to finish before the (user supplied) kernel `f` 
executes.

arg_set2 relates to Parameters!f

there is no logical room to put it, it belongs in neither of the 
two argument lists.


More information about the Digitalmars-d mailing list