4 ms·
The encoding of compound values as functions is actually more complicated than that: ;; pair constructor (defun make-pair (x y) (lambda (f)
by catnaroek 10y ago
The encoding of compound values as functions is actually more complicated than that:
;; pair constructor
(defun make-pair (x y)
(lambda (f)
(funcall f x y)))
;; projection from pairs
(defun former (x y) x)
(defun latter (x y) y)
;; test pairs
(defvar foo (make-pair 1 2))
(defvar bar (make-pair 1 2))
;; equality test
(defun equal-pairs (x y)
(and (equal (funcall x #'former) (funcall y #'former))
(equal (funcall x #'latter) (funcall y #'latter))))
;; try it
(equal-pairs foo bar)
And this was just for pairs of primitive values. You don't even want to imagine how painful it is to represent arbitrarily complex compound values this way.