Skip to content

Instantly share code, notes, and snippets.

@cronokirby
Created February 19, 2017 21:37
Show Gist options
  • Save cronokirby/494be3e5d2511152c44e9c1a4e05768b to your computer and use it in GitHub Desktop.
Save cronokirby/494be3e5d2511152c44e9c1a4e05768b to your computer and use it in GitHub Desktop.
defmacro thunk(b) do
quote do: fn -> unquote(b) end
end
defmacro a ~> b do
quote do
unquote(a) = thunk(eval(unquote(b)))
end
end
def eval(x) when is_function(x), do: eval(x.())
def eval(x), do: x
def foo(a), do: fn -> a + 1 end
def add, do: fn a -> fn b -> thunk(eval(a) + eval(b)) end end
def compose, do: fn f -> fn g -> fn x -> thunk(eval(f.(eval(g.(x))))) end end end
def map do
fn func ->
fn list ->
case eval(list) do
[] -> []
[head|tail] -> thunk([eval(func.(eval(head))) | eval(map().(func).(tail))])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment