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

The World Is Your Playground

Metaprogramming in Elixir is all about extensibility. Have you ever wished your favorite language would adopt that one neat feature? If you’re lucky, it might take years to happen. Often it never happens at all. In Elixir, you can introduce new first-class features at will. Take the familiar while loop that you find in most languages. It’s missing from Elixir, but you can imagine writing one like this:

 
while Process.alive?(pid) ​do
 
send pid, {self, :ping}
 
receive​ ​do
 
{^pid, :pong} -> IO.puts ​"Got pong"
 
after​ 2000 -> break
 
end
 
end

In the next chapter, we make this while loop a reality. It doesn’t stop there, though. With Elixir, we can define languages with the language, to express all kinds ...

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