Created
February 10, 2015 14:55
-
-
Save asterite/006baabf99c6db1ccfac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
record Cell, car, cdr | |
alias List = Nil | (-> Cell) | |
def inf(x = 0) | |
inf :: -> Cell | |
inf = -> { Cell.new(x, inf) } | |
end | |
def nat(x = 0) | |
->{ Cell.new(x, nat(x+1) as List) } | |
end | |
def cons(list, x) | |
->{ Cell.new(x, list) } | |
end | |
def car(list) | |
list.try &.call.car | |
end | |
def cdr(list) | |
list.try &.call.cdr | |
end | |
list = nat | |
10.times do | |
puts car(list) | |
list = cdr(list) | |
end | |
list = nil | |
ARGV.each do |x| | |
list = cons list, x | |
end | |
puts "===" | |
while list | |
puts car(list) | |
list = cdr(list) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment