Skip to content

Instantly share code, notes, and snippets.

@hamiltop
Created June 20, 2015 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamiltop/fec14c8ed6f0639df156 to your computer and use it in GitHub Desktop.
Save hamiltop/fec14c8ed6f0639df156 to your computer and use it in GitHub Desktop.
defmodule Test do
defmacro foo_macro(bar, block) do
IO.inspect bar
IO.inspect block
end
def foo(bar, block) do
IO.inspect bar
IO.inspect block
end
defmacro puts(string) do
IO.puts string
end
end
defmodule Run do
def run do
require Test
Test.puts "Macro with nums"
Test.foo_macro(1,2)
Test.puts "Macro with expr"
_ = Test.foo_macro(1 + 1, 2 + 2)
Test.puts "Macro with expr and do"
Test.foo_macro(1 + 1) do
2 + 2
end
Test.puts "macro with expr and explicit do keyword list"
Test.foo_macro(1 + 1, [do: 2 + 2])
IO.puts "function with nums"
Test.foo(1,2)
IO.puts "function with expr"
Test.foo(1 + 1, 2 + 2)
IO.puts "function with expr do"
Test.foo(1 + 1) do
2 + 2
end
IO.puts "function with expr and explicit do keyword list"
Test.foo(1 + 1, [do: 2 + 2])
end
end
Run.run
@hamiltop
Copy link
Author

Output elixir do_block.ex:

Macro with nums
1
2
Macro with expr
{:+, [line: 25], [1, 1]}
{:+, [line: 25], [2, 2]}
Macro with expr and do
{:+, [line: 28], [1, 1]}
[do: {:+, [line: 29], [2, 2]}]
macro with expr and explicit do keyword list
{:+, [line: 33], [1, 1]}
[do: {:+, [line: 33], [2, 2]}]
function with nums
1
2
function with expr
2
4
function with expr do
2
[do: 4]
function with expr and explicit do keyword list
2
[do: 4]

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