Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created October 27, 2017 00:19
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenderlove/9096abbd4c70610f48dacc90ae40761f to your computer and use it in GitHub Desktop.
Save tenderlove/9096abbd4c70610f48dacc90ae40761f to your computer and use it in GitHub Desktop.
cons = fn (a, b) -> fn x -> x.(a, b) end end
car = fn (p) -> p.(fn (q, _) -> q end) end
cdr = fn (p) -> p.(fn (_, q) -> q end) end
each = fn (list, func) ->
iter = fn (list, func, next) ->
(fn (a, nil) -> func.(a)
(a, b) -> func.(a); next.(b, func, next)
end).(car.(list), cdr.(list))
end
iter.(list, func, iter)
end
list = cons.("a", cons.("b", cons.("c", nil)))
each.(list, &IO.puts/1)
@ijunaid8989
Copy link

You wrote all this to print

iex(8)> each.(list, &IO.puts/1)
a
b
c
:ok

this?

@tenderlove
Copy link
Author

Yes

@kevinjonesevans
Copy link

kevinjonesevans commented Oct 29, 2017

I love it! Lisp/scheme is awesome

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