O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom Language Constructs

You’ve seen that macros allow you to effectively create your own keywords in the language, but they also allow Elixir to be flexible against future requirements. For example, instead of waiting for the language to add a parallel for comprehension, you could extend the built-in for macro with a new para macro that spawns processes to run the comprehensions in parallel. It could look something like this:

 
para(​for​ i <- 1..10 ​do​: i * 10)

If implemented, para would transform the for AST into code that runs the comprehension in parallel. The original code would gain just one natural para invocation while executing the built-in comprehension in an entirely new way. José gave us a solid language foundation that we can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required