So you mean a meta-circular OOP implementation, where the hosting language already has car, cdr and cons. Alright.
I thought what you wrote was supposed to be a primitive implementation of the functions.
Re:Lisp in about 200 lines of Ruby
by twilightsentry on Saturday November 14, 2009 @07:32PM
(#942397)
No, not really, unless you're running the code in a metacircular interpreter.
Imagine encoding the pair ('hello . 'world) into a function. You might say:
(lambda (msg)
(if (eq msg 'car) 'hello 'world))
You could get 'hello by applying that function to the 'car symbol, or 'world by applying it to anything else. Wrapping that in another function lets us generalise to any CAR/CDR. (lambda (car-value cdr-value)
(lambda (msg)
(if (eq msg 'car) car-value cdr-value)))
If mquander's explanation isn't enough, you might look at it using terms from the OO world: CAR takes a pair object and calls its 'car method.