3 ms·
> ...but, the functions are side-effectless, and guaranteed not to change, so you can just equal? the results. Just because (f 1) and (g 1) are equal, it doesn
by catnaroek 10y ago
> ...but, the functions are side-effectless, and guaranteed not to change, so you can just equal? the results.
Just because (f 1) and (g 1) are equal, it doesn't automatically follow that f and g are equal. Functions shouldn't be comparable for equality at runtime, because extensional equality of functions is undecidable.
- qwertyuiop924 10y agosigh not what I meant. I MEANT that you can model immutable variables using functions.
- catnaroek 10y agoWill `equal` work correctly on immutable values modeled as functions? No? I guessed just as much.
- qwertyuiop924 10y agowell, you'd have to unwrap the values first. The call would be: (equal variable (constant)) whether you think that's acceptable or not is up to you.
- catnaroek 10y agoThe 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.