digitalmars.D.learn - is there a difference between those two notations
- =?ISO-8859-1?Q?Christian_K=F6stlin?= (4/4) Apr 30 2012 reduce!((int a, int b){return a+b;})(iota(100))
- Jesse Phillips (6/10) Apr 30 2012 The answer to your question should be no. The second is
- Jonathan M Davis (6/10) Apr 30 2012 The first one directly creates a lambda, whereas the second one uses a s...
- =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= (6/16) Apr 30 2012 thanks a lot ... should have had a look in
- bearophile (9/11) Apr 30 2012 Today the syntaxes I prefer are:
- =?UTF-8?B?Q2hyaXN0aWFuIEvDtnN0bGlu?= (5/15) May 02 2012 thanks for this tip.
- Timon Gehr (3/7) Apr 30 2012 In this case there is not. But if external symbols are to be referred to...
reduce!((int a, int b){return a+b;})(iota(100)) reduce!("a+b")(iota(100)) thanks in advance christian koestlin
Apr 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 koestlinThe 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
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 advanceThe 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
On 04/30/2012 07:04 PM, Jonathan M Davis wrote:On Monday, April 30, 2012 17:19:00 Christian Köstlin wrote:thanks a lot ... should have had a look in https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm.d ... regards christian koestlinreduce!((int a, int b){return a+b;})(iota(100)) reduce!("a+b")(iota(100)) thanks in advanceThe 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
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
On 04/30/2012 11:03 PM, bearophile wrote:Christian Köstlin:thanks for this tip. i always forget about this nice d feature :) regards christianreduce!((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 02 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 koestlinIn 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