Use case for std.bind

Daniel Keep daniel.keep.lists at gmail.com
Tue Feb 24 06:50:22 PST 2009



Lars Kyllingstad wrote:
> Daniel Keep wrote:
>>
>> Lars Kyllingstad wrote:
>>> [snip]
>>>
>>> I for one like it, and would very much like to see such a syntax in D2.
>>> Also, I'd have it work with either of a function's arguments, not only
>>> the leading or trailing ones:
>>>
>>>   int foo(int a, int b, int c, int d) {...}
>>>   auto bar1 = foo(_, b, c, d);
>>>   auto bar2 = foo(a, b, c, _);
>>>   auto bar3 = foo(_, b, _, d);
>>>
>>>   assert (is (typeof(bar3) == int delegate(int, int)));
>>>
>>> In its simplest form, it would just be syntactic sugar for the delegate
>>> literal. But I'm curious: If foo is a pure function, couldn't the
>>> compiler perform some extra optimization here?
>>>
>>> -Lars
>>
>> auto a = b(_, c(_, x), _);
>>
>> What are the types of a, b and c?  What if b has multiple overloads or
>> is templated?
>>
>> Context-dependant grammar (let alone context-dependant single character
>> symbols): just say "no".
>>
>>   -- Daniel
> 
> Good point. How about this alternative syntax, then:
> 
>   auto bar3 = foo(int, b, int, d);
> 
> Will this also cause problems?
> 
> -Lars

This doesn't address the problem of what, exactly, the context of the
curried arguments is.  What's more, you're putting a type where an
expression is expected; I don't see how you get "currying" from
"repeating an argument type."

The problem I have with these suggestions are that you're basically
arguing for an incredibly inflexible, context-dependant, completely
unintuitive syntax for something you already have working syntax for.  I
just don't see the point.

  -- Daniel



More information about the Digitalmars-d mailing list