Lambda forms and discovered discrepancies...
Well, that silly example in the previous post always produces quoted cons items, never closures in any event...But along the way I discovered what appears to be a minor (unless you think it is major) discrepancy in LWM 5.02...
The CLHS states that CONSTANTLY could be defined as:
(defun constantly (object)
#'(lambda (&rest arguments) object))
If this were so, then object would be evaluated only once, at the time of the call to
(constantly object)
So, let's try it out...
(defun tst ()
(print "Hello!")
5)
(setf x (constantly (tst)) ;; should print Hello! and bind x to a function that always returns 5...
x ;; oops! It prints Hello! again...
x ;; and again...
So it appears that LWM has provided CONSTANTLY in the form:
(defmacro constantly (object)
(let ((ignored (gensym)))
`(lambda (&rest ,ignored)
,object)))
So, in other words, it ensures that any side effects will be repeatedly performed -- which could be considered correct. But on the other hand, one cannot use CONSTANTLY to provide memoization of object evaluation results.
Interesting...
David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ 85750
email: dbm@refined-audiometrics.com
phone: 1.520.390.3995
Skype: dbmcclain