Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created June 25, 2018 20:32
Show Gist options
  • Save tenderlove/908d016b611726389d03b887d63c49ca to your computer and use it in GitHub Desktop.
Save tenderlove/908d016b611726389d03b887d63c49ca to your computer and use it in GitHub Desktop.
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