def doesn’t capture its environment, so it won’t work directly.
You could do some AST surgery on what def produces:
{:def, [context: Elixir, import: Kernel],
[
{:run, [if_undefined: :apply, context: Elixir], Elixir},
[do: {:%{}, [], [value: PUT_THE_VALUE_HERE]}]
]}
but the pattern of “interpolate this compile-time value into the AST” is frequent enough that there’s a built-in mechanism for doing it… module attributes ![]()






















