In fact, let's go one step further

downs default_357-line at yahoo.de
Thu Jan 3 09:06:17 PST 2008


downs wrote:
> downs wrote:
>>  * ALTERNATIVE PROPOSAL *
>>
> 
> Let's modify this proposal a bit.
> 

In fact, let's go one step further.

How about this?

If a dgliteral is the last parameter to a function, say,

>
> int test(int x, int dgliteral() foo) {
>   ...
> }
>

then the following syntax shall be allowed:

>
> test(5) { writefln("Yay!"); }
>

To demonstrate what this would allow, consider this:

> int forall(T)(T[] array, int dgliteral(T) dl) {
>   foreach (entry; array) {
>     auto res = dl(entry);
>     if (res==1) return 0;
>     if (res==2) return 2;
>   }
>   return 0;
> }
>
>
> forall([2, 3, 4, 5]) (int x) { writefln(x); }
>

Not quite foreach in software yet, but we're getting there :)

IN FACT, while we're about it, let's warm up another old proposal: to consider (int x) writefln(x); a literal,
that is, to allow omitting the braces for single-statement literals.
I'm ready to argue that the benefits of this syntax in bringing literals in line with the behavior of most
of D's other statements outweigh the drawbacks of forbidding the arising ambiguities, if there even are any.


  As usual, what do you think?
 --downs



More information about the Digitalmars-d mailing list