Skip to content

Instantly share code, notes, and snippets.

@tmiller
Last active April 3, 2018 20:39
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 tmiller/2b3228b0d9a1e798662f527425c814d3 to your computer and use it in GitHub Desktop.
Save tmiller/2b3228b0d9a1e798662f527425c814d3 to your computer and use it in GitHub Desktop.
defmodule TenderList do
def cons(x, y), do: fn(m) -> m.(x,y) end
def car(cell), do: cell.(fn(x, _) -> x end)
def cdr(cell), do: cell.(fn(_, y) -> y end)
def test do
list = cons(1, cons(2, cons(3, 4)))
IO.puts car(list)
IO.puts car(cdr(list))
IO.puts car(cdr(cdr(list)))
end
end
-- https://repl.it/@tmiller/Tenderlang
cons x y = \m -> m x y
car cell = cell $ \x _ -> x
cdr cell = cell $ \_ y -> y
main = do
putStrLn $ show $ car list
putStrLn $ show $ car $ cdr list
putStrLn $ show $ car $ cdr $ cdr list
where
list = cons 1 $ cons 2 $ cons 3 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment