How have you used Metaprogramming in Elixir?

  1. For a private project I wrote a macro to write boilerplate for me, deriving a lot from schema’s. I did abandon the project long ago but now I am looking at Ash; as it is my dream come true.

  2. An experiment to have call stack based authorization, by decorating function calls. How to get name of 'calling' module and/or function?.

  3. PLR Uses metaprogramming to do all kinds of black magic by rewriting Phoenix routes and creating alternative helpers.

  4. PLR’s successor is Routex which also uses macro’s but aims at being less black magic.

Somewhere between 3 and 4 I read the Metaprogramming book from Chris McCord and some nice blog posts from @sasajuric.

Have fun with macro’s; escape into functions as soon as you possibly can and do not start writing macro’s that write macro’s :wink:

4 Likes