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

Getting Domain Specific

Before jumping into code, let’s look at what DSLs are all about and how metaprogramming makes them so easy. In Elixir, DSLs are languages defined by custom macros. They are a way to build a language within a language for solving a specific domain problem. In our case, our domain is HTML generation.

You’ve probably had experience with HTML generation in other languages where the string of HTML was produced by mixing source code within markup, parsing the file, and evaluating the result. These solutions work, but you often have to leave pure source code behind for a different template syntax. This requires yet another syntax to learn and context-switching between languages as your write your program.

Imagine if instead of ...

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