Mixin template evaluated to string can convert to string mixin expression implicitly

Timon Gehr timon.gehr at gmx.ch
Fri Jun 24 10:52:47 PDT 2011


Alex_Dovhal wrote:
> "Timon Gehr" <timon.gehr at gmx.ch> wrote:
>> String mixins themselves are 'a little bit ugly' (but unquestionably very
>> useful).
>> I think the syntax should keep reflecting that.
>>
>> Your proposal is a try to make up for Ds lack of macros. I'd prefer
>> macros.
>> Also overloading the meaning of 'mixin template' seems to be questionable.
>> As I
>> understand it, your proposal would make code like this valid?:
>>
>
>
> With Don's extension of CTFE and Kenji proposal it's possible to fully
> implement macroses in library. I've tried to do that earlier but it was
> impossible with current compiler state. I think it's GREAT idea. Thank Kenji
> for making it. I'm interested in implementing such macro library. Are there
> any instructions how to compile DMD under windows?

http://www.digitalmars.com/d/2.0/dmd-windows.html#compiling_dmd

Macros operate on ASTs, not strings. You won't get real macros, just something
that feels somewhat like them. You still could implement the equivalent to C
macros (not real macros either) in a library, but they would have all the problems
of C macros, as string mixins do now. (You make this fact explicit by typing "mixin").

For anything but the most trivial code transformations, you have to cheat the
compiler into parsing your code into an AST (further complicated by the fact that
you cannot overload all operators freely), use clever tricks to get the
information you want and then you have to transform it back into a string so that
it can then be mixed in (which of course requires reparsing the whole thing.) This
is just painful and a waste of cycles.

String mixins are useful, but they cannot replace macros.

What would your library be capable of?

Cheers,
-Timon


More information about the Digitalmars-d mailing list