On 7/11/14, 7:38 PM, Idan Arye wrote:
On Friday, 11 July 2014 at 17:00:32 UTC, Dicebot wrote:
Full macro system is not needed to implement it, just AST reflection
can do the trick (and has better fit with existing features).

Wouldn't AST reflection be more complex to implement&use than a macro
system? I mean, a macro system is quite functional in nature - the macro
takes AST arguments and return an AST that the compiler embeds into the
code. With AST reflection, you need to mutate an existing AST, which is
more complex because order of execution matters.

Also, what you want to do with an AST is definitely creating code. And, in my opinion, it's much easier to create code by writing it and not by creating the nodes.

Compare this:

macro logfx(exp)
  debug_log({{exp.stringify}})
  fx({{exp}})
end

To this:

macro logfx(exp)
  debug_log_call = Call.new("debug_log", StringLiteral.new(exp.to_s))
  fx_call = Call.new("fx", exp)
  Expressions.new [debug_log_call, fx_call]
end

The second one is very hard to understand and, if implemented with CTFE, will be much slower to execute.

Reply via email to