|
|
|
|
|
by TeMPOraL
4005 days ago
|
|
You get full AST access in Erlang as well. I don't know how it is in Elixir, but in Erlang you don't want to touch that feature with a ten foot pole. It's hairy and incredibly annoying to work with. I'm having a hard time to imagine how it couldn't be without homoiconicity and with that "actual syntax". I've been reading about macros in Scala recently, and they seem to suffer from the same problem - they just don't fit well with the rest of the language. |
|
It's pretty much the exact opposite in Elixir. The only thing you really have to wrap your head around is the switch between the quoting context and the unquoting context... which is pretty much no different from understanding macros period. The definition syntax looks just like a method definition, except it's "defmacro" instead of "def", and the macro body receives an AST instead of (or in addition to) your usual arguments. But I'm probably not doing it justice...
http://elixir-lang.org/getting-started/meta/macros.html
https://pragprog.com/book/cmelixir/metaprogramming-elixir
Here Dave Thomas creates a simple "returning" macro, you can just watch the screencast if you're feeling lazy: http://pragdave.me/blog/2014/11/05/a-simple-elixir-macro/