Skip to content

Instantly share code, notes, and snippets.

@asterite
Created February 10, 2015 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asterite/006baabf99c6db1ccfac to your computer and use it in GitHub Desktop.
Save asterite/006baabf99c6db1ccfac to your computer and use it in GitHub Desktop.
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