|
|
|
|
|
by resc1440
3902 days ago
|
|
Are macros useful in a web development context? I don't feel like I've been missing them in Django, but maybe I've just forgotten because it's been a long time since I wrote anything substantial in Scheme. (Are Elixir macros similar to Scheme macros?) |
|
Elixir macros are like Scheme macros; they're fully hygienic (no variable namespace issues), and they evaluate at compile time. The main difference is that Scheme's main syntax construction is the linked list, and Elixir uses a richer data structure, almost equivalent to JSON. Aside from the particular structure the macro's manipulating, the concepts are the same.
Elixir macros are also used idiomatically to allow "smart" loading of modules, e.g. specifying additional code to run in the caller's context rather than the callee's. They fit nicely for this purpose.