Created
June 25, 2018 20:32
-
-
Save tenderlove/908d016b611726389d03b887d63c49ca 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
cons = lambda { |a, b| | |
lambda { |m| m.call(a, b) } | |
} | |
car = lambda { |m| m.call(lambda { |a, _| a }) } | |
cdr = lambda { |m| m.call(lambda { |_, b| b }) } | |
# A list that only uses lambdas | |
list = cons.call(1, cons.call(2, cons.call(3, nil))) | |
p car.call(list) # => 1 | |
p car.call(cdr.call(list)) # => 2 | |
p car.call(cdr.call(cdr.call(list))) # => 3 | |
p cdr.call(cdr.call(cdr.call(list))) # => nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment