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

Generating Functions from External Data

Turning raw data into code might sound impractical, but it’s an extremely nice solution to a number of problems. Ever wonder how Elixir manages its fantastic String Unicode support? The way it goes about it is my favorite metaprogramming example to date. The String.Unicode module of the standard library dynamically generates thousands of function definitions from external data when compiled. These generated functions pattern match on all known Unicode characters to achieve the best Unicode support in languages today. Let’s look inside the String.Unicode module to understand how Elixir makes this happen.

Instead of manually mapping tens of thousands of Unicode code points into an Elixir data structure, a ...

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