Re: delegates and functions

2018-06-10 Thread drug via Digitalmars-d-learn
On 10.06.2018 20:58, SrMordred wrote: a => { return 2*a; }   /\  \   /   ||   \ /   ||    \   /   || \ /   ||  \   /  This is   \ /  function   \  This is definition of delegate  definition  \ so you have a function that returns delegate. ``` it's like a => a

Re: delegates and functions

2018-06-10 Thread SrMordred via Digitalmars-d-learn
a => { return 2*a; } /\ \ / || \ / ||\ / || \ / || \ / This is \ / function \ This is definition of delegate definition \ so you have a function that returns delegate. ``` it's like a => a => 2*a; or (a){ return () { return

Re: delegates and functions

2018-06-10 Thread drug via Digitalmars-d-learn
On 10.06.2018 12:21, OlegZ wrote: On Saturday, 9 June 2018 at 22:28:22 UTC, Ali Çehreli wrote: There is some explanation at the following page, of how the lambda syntax is related to the full syntax:   http://ddili.org/ders/d.en/lambda.html#ix_lambda.=%3E copy rect from article as image http

Re: delegates and functions

2018-06-10 Thread OlegZ via Digitalmars-d-learn
On Saturday, 9 June 2018 at 22:28:22 UTC, Ali Çehreli wrote: There is some explanation at the following page, of how the lambda syntax is related to the full syntax: http://ddili.org/ders/d.en/lambda.html#ix_lambda.=%3E copy rect from article as image https://i.gyazo.com/c23a9139688b7ed59fb

Re: delegates and functions

2018-06-09 Thread Ali Çehreli via Digitalmars-d-learn
On 06/09/2018 02:09 PM, OlegZ wrote: On Saturday, 9 June 2018 at 20:55:21 UTC, drug wrote: In fact using `=>` you really define a function returning delegate. I see. Thanks. There is some explanation at the following page, of how the lambda syntax is related to the full syntax: http://dd

Re: delegates and functions

2018-06-09 Thread OlegZ via Digitalmars-d-learn
On Saturday, 9 June 2018 at 20:55:21 UTC, drug wrote: In fact using `=>` you really define a function returning delegate. I see. Thanks.

Re: delegates and functions

2018-06-09 Thread drug via Digitalmars-d-learn
On 09.06.2018 23:39, OlegZ wrote: On Saturday, 9 June 2018 at 20:03:15 UTC, OlegZ wrote: auto hz = (string s) => { writeln( s ); return cast( int )s.length; } How I should to write lambda of type "int delegate( string )? I found one way: auto hz = delegate int( string s ) { writeln( s ); ret

Re: delegates and functions

2018-06-09 Thread OlegZ via Digitalmars-d-learn
On Saturday, 9 June 2018 at 20:03:15 UTC, OlegZ wrote: auto hz = (string s) => { writeln( s ); return cast( int )s.length; } How I should to write lambda of type "int delegate( string )? I found one way: auto hz = delegate int( string s ) { writeln( s ); return cast( int )s.length; }; but

delegates and functions

2018-06-09 Thread OlegZ via Digitalmars-d-learn
I want "int delegate( string )", but hz most probably is "int function( string )" auto hz = (string s) => { writeln( s ); return cast( int )s.length; }; but pragma (msg, typeid( (string s) => { writeln( s ); return cast( int )s.length; })); shows typeid( int delegate() @safe function(string s)