Re:Lisp in about 200 lines of Ruby
by mquander on Monday November 09, 2009 @10:05AM
(#930990)
Those look correct to me. The function returned by cons is just a switch that holds two values in a closure, and interprets what you pass it as a signal to determine which to retrieve. You could just as easily rewrite it to pass it 0 or 1 instead of car and cdr.
If you evaluate (car (cons 1 2)) and (cdr (cons 1 2)) on paper using substitution, you'll see how it works.
If you evaluate (car (cons 1 2)) and (cdr (cons 1 2)) on paper using substitution, you'll see how it works.