Skip to content

Instantly share code, notes, and snippets.

@henrik
Created Aug 29, 2020
Embed
What would you like to do?
Elixir "@foo bar" macro example
defmodule MyMacro do
defmacro @{name, _meta, [arg]} do
IO.inspect "Your #{name} is a #{arg}"
end
defmacro __using__(_) do
quote do
import Kernel, except: [@: 1]
import unquote(__MODULE__)
end
end
end
defmodule Example do
use MyMacro
@fruit "banana"
# Outputs "Your fruit is a banana" at compile time.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment