another idea for compile time functions
Andrei Alexandrescu (See Website For Email)
SeeWebsiteForEmail at erdani.org
Fri Feb 9 00:05:41 PST 2007
Yauheni Akhotnikau wrote:
> On Fri, 09 Feb 2007 08:42:37 +0300, Andrei Alexandrescu (See Website For
> Email) <SeeWebsiteForEmail at erdani.org> wrote:
>
>> The attribute is not even needed if meta-code is flagged as such. My
>> thoughts currently gravitate around the idea of using mixin as an
>> escape into compile-time world. Anything that's printed to standard
>> output in compile-time world becomes code, e.g. (using your function):
>>
>> mixin
>> {
>> writefln("int x = ", add(10, 20), ";");
>> }
>>
>> is entirely equivalent to:
>>
>> int x = 30;
>>
>> No annotation is needed on add because mixin clarifies that it's
>> called during compilation. The compiler will complain if add cannot be
>> user dually.
>>
>> Using mixin and write as separation devices makes it very clear what
>> is to be done when; otherwise, it quickly becomes confusing what code
>> is meant to actually get evaluated eagerly, and what code is to
>> actually be "output" for compilation.
>
> This is a good idea!
> But I think it is no need to iterpret 'pure D' code at compile time. If
> compiler sees such mixin expression it can create temporary D program
> which has content of the mixin expression and then execute it in
> background with standard output redirection (with help of rdmd).
I've said it before, this is useless. Metacode must have access to the
program's symbols.
Andrei
More information about the Digitalmars-d
mailing list