Thread overview
is there a difference between those two notations
Apr 30, 2012
Christian Köstlin
Apr 30, 2012
Jesse Phillips
Apr 30, 2012
Jonathan M Davis
Apr 30, 2012
Christian Köstlin
Apr 30, 2012
bearophile
May 02, 2012
Christian Köstlin
May 01, 2012
Timon Gehr
April 30, 2012
reduce!((int a, int b){return a+b;})(iota(100))
reduce!("a+b")(iota(100))

thanks in advance

christian koestlin
April 30, 2012
On Monday, 30 April 2012 at 15:19:02 UTC, Christian Köstlin wrote:
> reduce!((int a, int b){return a+b;})(iota(100))
> reduce!("a+b")(iota(100))
>
> thanks in advance
>
> christian koestlin

The answer to your question should be no. The second is transformed into a delegate like the first during compilation.

Note that there is also C# like lambdas

(a, b) => a+b
April 30, 2012
On Monday, April 30, 2012 17:19:00 Christian Köstlin wrote:
> reduce!((int a, int b){return a+b;})(iota(100))
> reduce!("a+b")(iota(100))
> 
> thanks in advance

The first one directly creates a lambda, whereas the second one uses a string mixin with std.function.binaryFunc to create a lambda. The lambda generated for the second one will be the same as the one given in the first. They're just different ways to do the same thing.

- Jonathan M Davis
April 30, 2012
On 04/30/2012 07:04 PM, Jonathan M Davis wrote:
> On Monday, April 30, 2012 17:19:00 Christian Köstlin wrote:
>> reduce!((int a, int b){return a+b;})(iota(100))
>> reduce!("a+b")(iota(100))
>>
>> thanks in advance
>
> The first one directly creates a lambda, whereas the second one uses a string
> mixin with std.function.binaryFunc to create a lambda. The lambda generated
> for the second one will be the same as the one given in the first. They're just
> different ways to do the same thing.
>
> - Jonathan M Davis
thanks a lot ... should have had a look in https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d ...

regards

christian koestlin
April 30, 2012
Christian Köstlin:

> reduce!((int a, int b){return a+b;})(iota(100))
> reduce!("a+b")(iota(100))

Today the syntaxes I prefer are:

iota(100).reduce!q{a + b}()

iota(100).reduce!((a, b) => a + b)()

But hopefully in some we'll have an efficient sum() function too in Phobos:

iota(100).sum()

Bye,
bearophile
May 01, 2012
On 04/30/2012 05:19 PM, Christian Köstlin wrote:
> reduce!((int a, int b){return a+b;})(iota(100))
> reduce!("a+b")(iota(100))
>
> thanks in advance
>
> christian koestlin

In this case there is not. But if external symbols are to be referred to inside the lambda, then the second notation cannot be used.
May 02, 2012
On 04/30/2012 11:03 PM, bearophile wrote:
> Christian Köstlin:
>
>> reduce!((int a, int b){return a+b;})(iota(100))
>> reduce!("a+b")(iota(100))
>
> Today the syntaxes I prefer are:
>
> iota(100).reduce!q{a + b}()
>
> iota(100).reduce!((a, b) => a + b)()
>
> But hopefully in some we'll have an efficient sum() function too in Phobos:
>
> iota(100).sum()
>
> Bye,
> bearophile
thanks for this tip.
i always forget about this nice d feature :)

regards

christian