Getting Started
Learn how metaprogramming can enable us to write incredible libraries much more efficiently.
We'll cover the following
What is metaprogramming?
Metaprogramming is an advanced programming concept that enables computer programs to treat other computer programs like their data.
Metaprogramming in Elixir is enabled by two factors:
- Abstract Syntax Tree (AST)
- Macros
The Abstract Syntax Tree (AST) in Elixir is exposed in a form that can be represented by Elixir’s own data structures. This property also gives us a natural syntax to interact with the AST. It lets us do powerful things in Elixir. Macros are a game changer. They open up unique possibilities that aren’t possible in most languages.
We’ll explore both of these concepts in detail in later chapters.
Metaprogramming is an essential feature
Metaprogramming is an interesting and essential language requirement. It puts us in control to extend the language to suit our project’s needs and lets us write powerful libraries that would be otherwise impossible.
If you have a web development background, and you work with Elixir, you’ll realize how well suited it would be for a web framework. Phoenix, an Elixir web framework, was born out of the realization that we could have the best of both worlds in a single web framework:
- A language that makes it a joy to write applications
- The runtime is fast and scalable.
With Elixir, Phoenix doesn’t have to choose between productivity and scalability. Metaprogramming gives us both.