Executing pure D at compile-time

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Thu Feb 8 11:42:03 PST 2007


kris wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> kris wrote:
>>
>>> Following on from the "Regex Redux thread, it seems to me there's an 
>>> easy way to execute pure D at compile-time. A few elements are needed:
>>>
>>> 1) the ability to describe a compile-time function call
>>> 2) the facility to pass arguments to it, and recieve a return value
>>> 3) a means of identifiying the D code to execute
>>> 4) a manner in which the pure D is executed
>>> 5) a mechanism for ensuring the executed code is docile
>>
>>
>> 6) Ensuring that the code executing at compile-time has full access to 
>> program's symbols.
>>
>> 1-5 define a way to define dual functions in D, which is a good thing. 
>> But without (6), they are useless.
> 
> On the contrary, they have access to the arguments passed to them; and 
> to thoose arguments only.
> 
> This should be viewed as a "good thing", since it sandboxes the extent 
> of behaviour. To do otherwise flies in the face of everything good about 
> encapsulation.

Symbols are interlinked. If you pass a class name to a metafunction, 
you'd sure hope to be able to access its base class name from there.

> Taking a step back though, what does it really matter? We're talking 
> about something that a diminishingly small number of programmers would 
> actually apply in everyday usage.
> 
> Thus, I would hope some serious 'trade off' consideration would be given 
> to such an approach. After all, there's that assertion that /used/ to be 
> on the D web site: the one about how D is a "practical language for 
> practical programmers" or something? Embedding yet another DSL into the 
> compiler would appear to be a long road for very little practical gain.

As discussed, there is plentiful evidence of an increase in effective 
use of advanced language technology for very practical applications. In 
Loki or Boost, only the limitations of C++, and the consequent explosion 
in complexity and palatability, have put a ceiling on the usefulness of 
the libraries - not the inability of library writers nor the backlash 
from "practical programmers". I think such an attitude does little to 
help the language and ultimately the very practical programmers that the 
concern is all about.

Walter told me that D didn't even have templates. Knowing Walter, I know 
he added them because he found them useful.


Andrei



More information about the Digitalmars-d mailing list