www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is there a difference between those two notations

reply =?ISO-8859-1?Q?Christian_K=F6stlin?= <christian.koestlin gmail.com> writes:
reduce!((int a, int b){return a+b;})(iota(100))
reduce!("a+b")(iota(100))

thanks in advance

christian koestlin
Apr 30 2012
next sibling parent "Jesse Phillips" <Jessekphillips+D gmail.com> writes:
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. (a, b) => a+b
Apr 30 2012
prev sibling next sibling parent reply "Jonathan M Davis" <jmdavisProg gmx.com> writes:
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
Apr 30 2012
parent =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= <christian.koestlin gmail.com> writes:
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
Apr 30 2012
prev sibling next sibling parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Apr 30 2012
parent =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= <christian.koestlin gmail.com> writes:
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
May 02 2012
prev sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
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.
Apr 30 2012