Skip to content

Instantly share code, notes, and snippets.

@dmitryn
Created May 31, 2012 18:49
Show Gist options
  • Select an option

  • Save dmitryn/2845359 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryn/2845359 to your computer and use it in GitHub Desktop.
Lambda calculus
def cons(x,y)
lambda {|m|
m.call(x,
y,
lambda {|n| x = n},
lambda {|n| y = n}
)
}
end
def car(x)
x.call(
lambda {|a, d, sa, sd| a}
)
end
def cdr(x)
x.call(
lambda {|a, d, sa, sd| d}
)
end
def set_car!(x, y)
x.call(
lambda {|a, d, sa, sd| sa.call(y)}
)
end
def set_cdr!(x, y)
x.call(
lambda {|a, d, sa, sd| sd.call(y)}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment