Skip to content

Instantly share code, notes, and snippets.

@henrik
Created August 29, 2020 20:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henrik/29030710ff7b0c8379204fdd7017c2fc to your computer and use it in GitHub Desktop.
Save henrik/29030710ff7b0c8379204fdd7017c2fc to your computer and use it in GitHub Desktop.
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