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 ...

Get Metaprogramming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.