Created
February 19, 2017 21:37
-
-
Save cronokirby/494be3e5d2511152c44e9c1a4e05768b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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