3 ms·
You don't need cons, car, cdr, etc. They can all be implemented using lambda. For example: ;; excuse my possibly hybrid notation (defun cons (car cdr)
by prestonbriggs 8y ago
You don't need cons, car, cdr, etc.
They can all be implemented using lambda.
For example:
;; excuse my possibly hybrid notation
(defun cons (car cdr)
(lambda (m)
(if (eq? m 'car) car
(if (eq? m 'cdr) cdr
nil))))
(defun car (obj) (obj 'car))
(defun cdr (obj) (obj 'cdr))
- sevensor 8y agoThis is neat, but doesn't it beg the question a little bit? You've used a conditional here in your definition. Can you define cond using only lambdas? (My apologies if the linked article does this, I haven't made it all the way through yet.)
- edflsafoiewq 8y agoYes. You encode true as λx.λy.x and false as λx.λy.y and then (if p then a else b) becomes just (p a b). See https://en.wikipedia.org/wiki/Church_encoding#Church_Booleans https://en.wikipedia.org/wiki/Church_encoding#Church_Boolean.... That page also has encodings of pairs and lists.
- sevensor 8y agoWhoa. That's really cool! Thanks for the link.