3 ms·
You have macros in Elixir
by schpaencoder 8y ago
You have macros in Elixir
- PopeDotNinja 8y agoErlang has macros... http://www1.erlang.org/documentation/doc-4.8.2/doc/extensions/macros.html http://www1.erlang.org/documentation/doc-4.8.2/doc/extension... ...but I think they work differently, or are more limited in scope.
- ramchip 8y agoErlang 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/unicode/unicode.ex 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_spec/gen_unicode_mod.escript#L279 https://github.com/erlang/otp/blob/OTP-21.2/lib/stdlib/uc_sp...