reduce!"a+b"(R) syntax question

Timon Gehr timon.gehr at gmx.ch
Tue Aug 21 10:26:36 PDT 2012


On 08/21/2012 07:05 PM, Andrew Spott wrote:
> When I'm doing an anonymous function for something like reduce,
> how are the arguments determined?  Is it alphabetical?  Can I use
> any names (reduce!"d-c"(R)?), or are the names defined in the
> function "reduce"?

They are defined here:
http://dlang.org/phobos/std_functional.html#binaryFun

>
> This syntax isn't really documented at all in the language
> reference, which makes it a little bit of guess work.
>

This is not part of the language, it is a library artefact:
http://dlang.org/phobos/std_algorithm.html

'Many functions in this module are parameterized with a function or a 
predicate. The predicate may be passed either as a function name, a 
delegate name, a functor name, or a compile-time string. The string may 
consist of any legal D expression that uses the symbol a (for unary 
functions) or the symbols a and b (for binary functions). These names 
will NOT interfere with other homonym symbols in user code because they 
are evaluated in a different context. The default for all binary 
comparison predicates is "a == b" for unordered operations and "a < b" 
for ordered operations.'


More information about the Digitalmars-d-learn mailing list