[Openmcl-devel] bug?

Paul Krueger plkrueger at comcast.net
Mon Dec 7 14:36:41 PST 2009

Is the following a bug or does the standard permit the following  

Welcome to Clozure Common Lisp Version 1.5-dev-r13174M-trunk   
?  (setf ls (list 1 2 3 'a 0 1 2 3))
(1 2 3 A 0 1 2 3)
? (plusp 0)
? (find-if-not #'plusp ls :from-end t)
 > Error: value A is not of the expected type REAL.
 > While executing: PLUSP, in process Listener-2(7).
 > Type cmd-. to abort, cmd-\ for a list of available restarts.
 > Type :? for other options.
1 >

I guess I would have expected that if the ":from-end t" was honored  
that #'plusp would never be called on the 'a element, but obviously  
that isn't the case.

And if you happen to use a test that has side-effects, e.g.

? (defvar *count* 0)
? (defun #'plusp-with-side-effects (arg)
     (when (plusp arg)
       (incf *count*)))
? (setf ls2 '(1 2 3 0 1 2 3))
(1 2 3 0 1 2 3)
? (find-if #'plusp-with-side-effects ls2 :from-end t)
? *count*

(trying to count how many positive numbers occur at the end of the  
list) then you may not get what you expect.

You don't see this behavior if you search from the beginning of a list  
or search backward through an array. It's as if someone decided that  
since you have to traverse the list to find the end anyway that you  
might as well run the test as you go. I suppose I can nreverse my list  
and search forward to avoid this now that I know what it's doing ...


More information about the Openmcl-devel mailing list