lazy redux

Leandro Lucarella llucax at gmail.com
Mon Dec 7 11:49:49 PST 2009


Michal Minich, el  7 de diciembre a las 13:17 me escribiste:
> Hello bearophile,
> 
> >Michal Minich:
> >
> >>But introduction "{ epx }" as delegate/function literal for functions
> >>with no arguments, which implicitly returns result of the expression,
> >>seems to me as a good idea.
> >>
> >It's a special case, and special cases help to kill languages. It's
> >not important enough.
> >But a general shorter syntax for lambdas is possible, like the C# one.
> >Evaluations lazy arguments only 0 or 1 times sounds like a nice idea.
> >Bye,
> >bearophile
> 
> Yes, it works well in C#, and it is one of the best extension of
> this language (only adding generics was better).
> 
> Consider how it works in C#, and how it could in D
> 
> // 1. lambda with no parameter  int a;
> var t = new Thread (  () => a=42  );
> 
> // 2. lambda with one parameter
> string[] arr;
> Array.FindAll (arr, item => item.Contains ("abc"));
> // 3. lambda with more parameters
> Foo (  (a, b) => a + b );
> 
> // 4. lambda with statement (previous examples were expressions)
> Array.FindAll (arr, item =>  { return item.Contains ("abc"); } );
> // curly braces, semicolon and return are required when statement is used.
> 
> D could use:
> 
> 1. auto t = new Thread ( { a=42 } );

I think this syntax is pretty neat, because it's make the caller
intentions explicit (and it's very compact). For example, if you write:
  foo({bar()});
Is more obvious that bar() might not be even called. Is like explicit
reference passing (which D doesn't have unfortunately).

I don't know if it's doable though, maybe it's ambiguous?

-- 
Leandro Lucarella (AKA luca)                     http://llucax.com.ar/
----------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------
MP: Cómo está, estimado Bellini?   B: Muy bien, Mario, oraculizando.
MP: Qué tengo?                     B: El auto mal estacionado.
MP: No, en mi mano, Bellini...     B: Una murga!
MP: No, escuche bien. Es de lona.  B: Un ring, Mario.
MP: No Bellini. Tiene cordones.    B: La vereda.
MP: No Bellini! Muy fácil, eh! Es  B: Una modelo, Mario!
    imprescindible para jugar al   B: Un negro, Mario.
    basquet.
MP: No, Bellini, no y no!
	-- El Gran Bellini (Mario Podestá con unas zapatillas de basquet)



More information about the Digitalmars-d mailing list