Chapter 3Advanced Compile-Time Code Generation
So far we’ve performed compile-time code generation through careful use of macros. Now let’s shift gears and exploit Elixir’s module system. With advanced metaprogramming, we can embed data and behavior within modules directly from outside sources of information. This technique can remove countless lines of boilerplate, while producing highly optimized programs. We’ll start by exploring how Elixir embeds an entire unicode database at compile time for its robust Unicode support. Next, we’ll build MIME-type validation and internationalization libraries, while applying compile-time optimizations that aren’t possible in many languages. Knowing when and where to use this technique will allow us to construct ...
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.