DMD 1.005 release
Pragma
ericanderton at yahoo.removeme.com
Tue Feb 6 09:42:24 PST 2007
BLS wrote:
> Pragma schrieb:
>> BLS wrote:
>>
>>> I guess here is a need for further explaination.
>>>
>>> Either I am an complete idiot (not completely unrealistic) and
>>> missunderstood something, or a new, quit radical, programming
>>> paradigmn change is on it s way. I mean it is difficult to realize
>>> the implications.
>>> Bjoern
>>
>>
>> Just try to wrap your head around this:
>> http://www.digitalmars.com/d/mixin.html
>>
>> template GenStruct(char[] Name, char[] M1)
>> {
>> const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
>> }
>>
>> mixin(GenStruct!("Foo", "bar"));
>>
>> //which generates:
>>
>> struct Foo { int bar; }
>>
>> In short this means that we can have *100%* arbitrary code generation
>> at compile time, w/o need of a new grammar to support the capability.
>>
>
> Hi Eric,
> I am able to read and understand the code. (not nessesarily the far
> reaching implications)
> But the generated code is still D. So what does it mean :
> Walter Bright schrieb:
> > The idea is to enable the creation of DSLs (Domain Specific Languages)
> How ?
> Bjoern
I think you answered your own question. :)
Take the compile-time regexp lib that Don and I wrote a while back. Technically, Regular-expressions are a DSL of
sorts. This feature just makes the implementation of stuff like that easier. The end result will still be D code.
auto widget = CreateNewWidget!("Some DSL Code");
I was confused too, since the wording could be interpreted as allowing you to just code in some other language, wherever
you want. This is not the case. Ultimately, any DSL implemented in this fashion is going to have to operate on static
strings.
> I can imagine the following scenario : D Compiler is calling a
> Translator, a modified Enki f.i. to translate a Domain Specific Language
> into D ... strange
I've thought about that too- much like BCS's work. The only thing keeping me from doing this *was* that the code
generated would be largely inferior to that created by an external program. Thanks to the new syntax of mixin(), this
is no longer the case.
--
- EricAnderton at yahoo
More information about the Digitalmars-d-announce
mailing list