Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
855 stars 103 forks source link

(COND NIL) does not error #318

Closed phoe closed 4 years ago

phoe commented 4 years ago

A bugreport came via mail to me:


Dear Michal,

Last year and this year, I send a mail about the bug to xrme but no response. I hope you can check it.

sbcl> (cond nil) => COND clause is not a CONS: NIL.
ecl> (cond nil) => COND: Illegal clause NIL.
cmucl> (cond nil) => Cond clause should be a non-empty list: NIL.
clisp> (cond nil) => COND: clause NIL should be a list.
acl> (cond nil) => Error: NIL -- Illegal atomic clause in COND.
lispworks> (cond nil) => Error: NIL -- Illegal atomic clause in COND.

ccl> (cond nil) => nil

From CLHS:

cond {clause} => result clause::= (test-form form*)

Obviously test-form is required. So simple a bug, a famous implementation!

Solution:

(defmacro cond (&rest args &aux clause)
  (when args
     (setq clause (car args))
     (when (atom clause)
        (error "Cond clause should be a non-empty list: ~S.") clause)
     (if (cdr clause)        
         `(if ,(car clause) (progn ,@(cdr clause)) (cond ,@(cdr args)))
       (if (cdr args) `(or ,(car clause) (cond ,@(cdr args)))
                      `(values ,(car clause))))))

Sincerely Fengjing Xiao

xrme commented 4 years ago

fixed in 417f576e4c7.