But... I don't want my delegates to be lazy - breeding advice
Andy Knowles
andy.knowles at gmail.com
Thu Aug 24 00:23:23 PDT 2006
Walter Bright wrote:
> Ok, I've thought about it a bit:
>
> void foo(int x); // same as before 0.165
> void foo(int delegate() x) // same as before 0.165
>
> and now:
>
> void foo(lazy int x);
>
> In other words, 'lazy' is now a parameter storage class. This means that:
>
> void foo(int x);
> void foo(lazy int x);
>
> cannot be distinguished based on overloading, but:
>
> void foo(lazy int x);
> void foo(int delegate() x);
>
> can be. The implicit conversion of a value to a delegate returning that
> value would be removed. The conversion happens always (not implicitly)
> if the parameter storage class is 'lazy'.
I think that is definitely a step in the right direction, and I think it
will make people a lot more comfortable.
Some questions:
1) While in void foo(lazy int x) will x be evaluated using x() or just
x? Either one could lead to confusion.
2) What are your thoughts on allowing {2*x} as a shortcut for { return
2*x; }? This would only apply to delegates of course, but may still be
useful in places.
3) Any thoughts on a shortcut syntax for arguments to delegates? It
would be nice to be able to write:
int[] map(int[] arr, int delegate(int) func);
int[] b = map(a, (x){ 2*x });
or something similar. At the moment we must write either:
int[] map(int[] arr, int delegate(int) func);
int[] b = map(a, (int x){ return 2*x; });
or:
int[] map(int[] arr, out int arg, lazy int func);
int x;
int[] b = map(a, x, 2*x);
Andy
More information about the Digitalmars-d
mailing list