Hacker News new | ask | show | jobs
by schpaencoder 2742 days ago
You have macros in Elixir
1 comments

Erlang has macros...

http://www1.erlang.org/documentation/doc-4.8.2/doc/extension...

...but I think they work differently, or are more limited in scope.

Erlang macros are basically text substitution. It's similar to C pre-processor directives.

Elixir macros are a completely different beast, they can manipulate the AST Lisp-style. A very elegant example is Elixir's unicode module, which reads unicode data tables and turns them into function definitions at compile time [1].

Compare this to the equivalent module in plain old Erlang, which has to be generated by a separate script, in a pre-compilation step in the Makefile, that literally prints blocks of code [2].

[1] https://github.com/elixir-lang/elixir/blob/v1.7.4/lib/elixir...

[2] https://github.com/erlang/otp/blob/OTP-21.2/lib/stdlib/uc_sp...