April 27, 2007
"Walter Bright" <newshound1@digitalmars.com> wrote in message news:f0s9gr$u05$1@digitalmars.com...
> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
>
> http://www.digitalmars.com/d/changelog.html
>
> http://ftp.digitalmars.com/dmd.1.014.zip

Yay for struct literals, but now static and dynamic initialization of structs are completely different.  Static looks like this:

static S s = {a : 1, b : 2, c : 3};

and dynamic:

S s = S(1, 2, 3);

Not only do they look completely different, but you also can't use named members with the dynamic syntax like you can with the static.

Is there any ambiguity to the syntax:

S s = S{a : 1, c : 3, b : 2};

That is, just an Ident followed by a static struct initializer?


April 27, 2007
Walter Bright wrote:
> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
> 
> http://www.digitalmars.com/d/changelog.html
> 
> http://ftp.digitalmars.com/dmd.1.014.zip

Fantastic!  Thanks Walter!

::places ear to ground::

Yep. It's a stampede alright... code generators.  Lots of 'em.

-- 
- EricAnderton at yahoo
April 27, 2007
Walter Bright wrote:
> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
> 
> http://www.digitalmars.com/d/changelog.html
> 
> http://ftp.digitalmars.com/dmd.1.014.zip

I probably don't say this enough: Thanks!
~ Clay
April 27, 2007
Don Clugston wrote:
> 
> In practice, you _can_ have initialized static AAs, provided they are read-only (which is probably the main time you want to supply initializers). The declaration syntax for a read-only AA slightly lacks syntactic sugar, but the syntax for usage is perfect:
> 
> char[][uint] symTable() { return [2u:"he",4:"ho",6:"hi"]; }
> 
> void main()
> {
>     for (int k=1; k<=6; ++k) {
>         if ((k&1)==0) printf("%.*s\n", symTable[k]);
>     }
> }
> 

function call overhead on every use? Ouch!!

I'd rather go with

char[][uint] symTable; static this(){symTable=[2u:"he",4:"ho",6:"hi"];}
April 27, 2007
Pragma wrote:
> Walter Bright wrote:
> 
>> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
>>
>> http://www.digitalmars.com/d/changelog.html
>>
>> http://ftp.digitalmars.com/dmd.1.014.zip
> 
> 
> Fantastic!  Thanks Walter!
> 
> ::places ear to ground::
> 
> Yep. It's a stampede alright... code generators.  Lots of 'em.
> 

This is what I'm waiting for:

#!/usr/bin/dmd -c -o- > your_code.o

import comp.time.comp;

pragma(msg, D2ELF!(import("your_code.d"));
April 27, 2007
BCS wrote:
> Pragma wrote:
>> Walter Bright wrote:
>>
>>> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
>>>
>>> http://www.digitalmars.com/d/changelog.html
>>>
>>> http://ftp.digitalmars.com/dmd.1.014.zip
>>
>>
>> Fantastic!  Thanks Walter!
>>
>> ::places ear to ground::
>>
>> Yep. It's a stampede alright... code generators.  Lots of 'em.
>>
> 
> This is what I'm waiting for:
> 
> #!/usr/bin/dmd -c -o- > your_code.o
> 
> import comp.time.comp;
> 
> pragma(msg, D2ELF!(import("your_code.d"));

Apart from sheer curiosity, or for bragging rights, why would you want to completely re-implement the compiler backend as compile-time code?

-- 
- EricAnderton at yahoo
April 27, 2007
 Why the release date is shown as Apr 20, 2007 (on the changelog web page)? A typo?


Walter Bright Wrote:

> Sports associative array literals, and struct literals. This enables compile time function execution to work with symbol tables (AA's) and user defined types.
> 
> http://www.digitalmars.com/d/changelog.html
> 
> http://ftp.digitalmars.com/dmd.1.014.zip

April 27, 2007
Pragma wrote:
> BCS wrote:
> 
>> #!/usr/bin/dmd -c -o- > your_code.o
>>
>> import comp.time.comp;
>>
>> pragma(msg, D2ELF!(import("your_code.d"));
> 
> 
> Apart from sheer curiosity,

that and perversity about sums it up

> or for bragging rights, why would you want to completely re-implement the compiler backend as compile-time code?
> 

who said anything about just the backend? I'm thinking do the whole thing!!

Then again, I've been told I'm totally nuts.
April 27, 2007
BCS wrote:
> Pragma wrote:
>> BCS wrote:
>>
>>> #!/usr/bin/dmd -c -o- > your_code.o
>>>
>>> import comp.time.comp;
>>>
>>> pragma(msg, D2ELF!(import("your_code.d"));
>>
>>
>> Apart from sheer curiosity,
> 
> that and perversity about sums it up
> 
>> or for bragging rights, why would you want to completely re-implement the compiler backend as compile-time code?
>>
> 
> who said anything about just the backend? I'm thinking do the whole thing!!

Pragma: This is madness!
BCS: No. This, is metaprogramming!
BCS: *kick*

> 
> Then again, I've been told I'm totally nuts.

No, you (along with Don and myself) are pushing D towards it's ultimate destination: de-throning C as the language of choice for obfuscated programming contests.

Jebus help us all.

-- 
- EricAnderton at yahoo
April 27, 2007
Frits van Bommel a écrit :
> bobef wrote:
>> this class member:
>>
>> static auto allsupportedfiles2=["avi":1,"mpg":1,"mpeg":1,"asf":1,"asx":1,"dat":1,"vob":1,"ifo":1,"wma":1,"wmv":1,"mov":1,"qt":1,"mp4":1,"fli":1,"rm":1,"nuv":1,"ogg":1,"ogm":1,"sdp":1,"pva":1,"roq":1,"flm":1,"cpk":1,"vivo":1,"mkv":1,"mp3":1,"mpe":1,"divx":1,"mpv":1,"m1v":1,"m2v":1,"dv":1,"m4v":1,"264":1,"mp1":1,"mp2":1,"mpa":1,"ac3":1,"m4a":1,"26l":1,"jsv":1,"wav":1/*,"rpl"*/,"flv":1]; 
>>
>>
>> app.d(126): Error: cannot infer type from this array initializer
>>
>> static bool[char[]] allsupportedfiles2=["avi":1,"mpg":1,"mpeg":1,"asf":1,"asx":1,"dat":1,"vob":1,"ifo":1,"wma":1,"wmv":1,"mov":1,"qt":1,"mp4":1,"fli":1,"rm":1,"nuv":1,"ogg":1,"ogm":1,"sdp":1,"pva":1,"roq":1,"flm":1,"cpk":1,"vivo":1,"mkv":1,"mp3":1,"mpe":1,"divx":1,"mpv":1,"m1v":1,"m2v":1,"dv":1,"m4v":1,"264":1,"mp1":1,"mp2":1,"mpa":1,"ac3":1,"m4a":1,"26l":1,"jsv":1,"wav":1/*,"rpl"*/,"flv":1]; 
>>
>>
>> app.d(126): Error: cannot use array to initialize bool[char[]]
>>
>>
>> why?
> 
> I guess that's what this sentence in the docs means:
> =====
> An AssocArrayLiteral cannot be used to statically initialize anything.
> =====
> (Note: The docs aren't up on the site yet, but you can find this in dmd/html/d/expression.html#AssocArrayLiteral)
> 
> The error message could be clearer.

One thing I don't understand is why this restriction on static assignment with AA initialisation exist?

In my head, static assignment of compile time assignment is more or less equivalent, so I find this weird..


I think that there are too many special cases in D:
- initialisation with literals works for normal assignment not for static
- in works for AA but not for array
- array initialisation count elements for dynamic arrays but not for array with fixed length.
etc.

Hopefully with macros it'll be possible to make D a bit more coherent (a generic call 'by keyword' a la Smalltalk would be nice), all those special cases are not fun to remember..

renoX