opening it up with Common Lisp
Book review: Darwinia
Summer reading: Spin
the Omnivoire's Delimma
the Golem's Eye
(Update, don't read this. I make a minor fool of myself and now I feel embarrassed).
(let* ((*a* 1) (f (lambda (&rest args) (declare (ignore args)) *a*))) (print (funcall f)) (let ((*a* 3)) (print (funcall f))) (values))
print? If you guessed "1, then 3" then you were correct. How about:
(let* ((*a* 1) (f (constantly *a*))) (print (funcall f)) (let ((*a* 3)) (print (funcall f))) (values))
If you guessed "1, then 3" then you disagree with every Lisp I've asked. I've tried this with and without optimizations and assume that the compilers are being clever with the constantly (even though CLTL2 says that constantly can be defined as:
(defun constantly (object) #'(lambda (&rest arguments) object))
I don't know the standard backwards and forwards well enough to say that one answer is better than another. Does anyone else know chapter and verse?
Copyright -- Gary Warren King, 2004 - 2006