Is it possible to handle 'magic' property assignments a'la PHP?
Jacob Carlborg
doob at me.com
Tue Jan 7 12:18:48 PST 2014
On 2014-01-07 16:58, H. S. Teoh wrote:
> Y'know, I've always wanted "trailing delegate syntax":
>
> func(x, y, z; p, q, r) {
> // body
> }
>
> gets translated into:
>
> func(p, q, r, (x, y, z) => /* body */);
>
> Since we already have UFCS, which translates a leading fragment into the
> first argument (x.func(y) --> func(x,y)), it seems perfectly reasonable
> to do something with the final argument too, like the above.
>
> This would allow one to implement, for example, foreach_reverse as a
> library function instead of a language keyword:
>
> void foreach_reverse(I, R)(R range, void delegate(I) dg)
> {
> ...
> dg(idx);
> ...
> }
>
> // Gets translated to:
> // foreach_reverse(range, (uint i) => /* body */);
> foreach_reverse (uint i; range) {
> ... // body
> }
>
> // And you can use UFCS too:
> range.foreach_reverse(uint i) {
> ... // body
> }
Exactly, that's what it is for. Perhaps supporting an alias parameter
would be good as well, since those are inlined:
void foo (alias dg) ();
foo {
// body
}
Translated to:
foo!({
// body
});
> I'm not holding my breath on this one, though. It's a rather big change
> and ultimately is just syntactic sugar. Maybe it can go on the list of
> features for D3... ;-)
I've brought this up before. If I recall correctly, it didn't was that
much resistance as one could think. Although this was before we had the
lambda syntax.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list