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

Chapter 5Creating an HTML Domain-Specific Language

One of the most powerful ways to use macros is to build domain-specific languages (DSLs). They let you create a custom layer in the language to attack problems closer to your application domain. This can make your code easier to write and make it more clearly represent the problem being solved. With DSLs, you can codify your business requirements and operate at a shared level of abstraction with the callers of your library.

Let’s extend the tools you’ve learned so far to create an HTML DSL. We’ll start by seeing what domain-specific languages are all about. Next, we’ll build a complete HTML DSL that generates templates from pure Elixir code. While building our library, we’ll uncover a few advanced ...

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