Search⌘ K
AI Features

Using Bindings to Inject Values

Explore how to inject values into Elixir macros using bindings, distinguishing this from unquote. Understand how bindings provide runtime values to quoted code blocks, allowing dynamic function definitions during macro expansion.

We'll cover the following...

Methods

Remember that there are two ways of injecting values into quoted blocks. One is unquote. The other is to use bindings.

However, the two have different uses and different semantics.

A binding is simply a keyword list of variable names and their values. When we pass a binding to quote, the variables are set inside the body of that quote.

This is useful because macros are executed at compile time. This means they don’t have access to values that are calculated at ...