How can I dump an expression into log and execute it

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Sun Jul 13 03:25:50 PDT 2014


On 2014-07-12 01:46, Idan Arye wrote:

> I assume "read-only" reflection means that functions produce ASTs that
> are directly embedded into the code(rather than modifying the AST of
> existing code) which is the same as with macros.

No, I'm pretty sure he means you can only reflect on the AST. Not 
produce new a new AST that will be inserted somewhere.


> I would like to see an AST based macro system, where `mixin` can accept
> ASTs and the `macro` keyword is an attribute for function arguments that
> turns them into ASTs. With this, we don't need special syntax to create
> ASTs on the fly - we can have a simple `toAST` library function:
>
>      AST(T) toAST(T)(macro(T) expr){
>          return expr;
>      }
>
> Note that `expr` is of type `AST(T)` - `macro` converts arguments of
> type `T` to `AST(T)` just like `lazy` converts arguments of type `T` to
> `T delegate()`.
>
>
> The OP's function macro will look like this:
>
>      AST(void) debugLog(T)(macro(T) expr){
>          auto printStatement=toAST(writeln(expr.toString()));
>          return new AST!(void)(printStatement,expr);
>      }
>
>      mixin(debugLog(x+10));

Here's my current proposal: http://wiki.dlang.org/DIP50

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list