DMD 1.014 release (struct literal syntax and keywords)

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Apr 30 18:05:54 PDT 2007


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:f161g5$2kno$1 at digitalmars.com...
> I like your suggestion better.  Walter's way takes us back to the 
> error-prone, fragile, mystery-meat way of constructing structs that they 
> tossed out in C99.  Ok, not "tossed out" but "provided an alternative to."
>
> Walter's way, however, gives you a way to transition from quick and dirty 
> usage like
>   struct Coord{ float x; float y; }
>   func(Coord(xval,yval));
> to something more complex via static opCall.

I thought about that too.  It just doesn't seem like a very compelling 
argument, especially considering that the language already has a perfectly 
good syntax for static struct literals.

> If you treat a keyword function as functions of one anonymous struct then 
> you're pretty much there.  For instance this:
>
>    void a_keyword_func({int a=10, int b=4, int c=20}) {. . .}
>
>    a_keyword_func(c:10, a:1);
>
> could be treated as
>
>    struct _S { int a=10; int b=4; int c=20; }
>    a_keyword_func( _S ) { . . . }
>
>    a_keyword_func( _S{c:10, a:1} );  //using your struct literals

I like the idea.  It also seems relatively unambiguous to parse.  Any colon 
in the param list of a call would signal use of names parameters, and the 
compiler would be able to check the function for any named params it has. 





More information about the Digitalmars-d-announce mailing list