Skip to content

Instantly share code, notes, and snippets.

@killme2008
Created October 23, 2015 03:55
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 killme2008/54381ae5f1bb2642d0cf to your computer and use it in GitHub Desktop.
Save killme2008/54381ae5f1bb2642d0cf to your computer and use it in GitHub Desktop.
Elixir macro example
defmodule MyUnless do
defmacro unless(clause, then_clause, else_clause \\ nil) do
quote do
if !unquote(clause) do
unquote(then_clause)
else
unquote(else_clause)
end
end
end
end
@killme2008
Copy link
Author

(defmacro unless [test then else]
  `(if-not ~test 
             ~then 
             ~else))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment