Hello all, first bug report.

Using gentoo, 2.6.29 kernel, sbcl 1.0.19, there is a possible error.

Compare the following MACROEXPAND-1 applications of the following two definitions of macros:

(defmacro fails-during-exp (name &key a)
  `(defpackage ,name ,(when a "a exists")))

(defmacro succs-during-exp (name &key a)
  `(some-name ,name ,(when a "a exists")))

Notice that the first macro has the symbol 'defpackage.

(macroexpand-1 '(fails-during-exp "abcd" :a t)) runs fine
(macroexpand-1 '(succs-during-exp "abcd" :a t)) runs fine
(macroexpand-1 '(succs-during-exp "abcd")) runs fine
(macroexpand-1 '(fails-during-exp "abcd")) results in an error

error in FORMAT: no more arguments
  ~:<~W~^ ~3I~:_~W~^~1I~@{~:@_~:<~W~^ ~:I~@_~@{~W~^ ~_~}~:>~}~:>
                                  ^
   [Condition of type SB-FORMAT:FORMAT-ERROR]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" RUNNING {1002C73DE1}>)

Backtrace:
  0: ((LABELS #:WITH-CIRCULARITY-DETECTION-BODY-3980))
  1: ((LABELS #:WITH-CIRCULARITY-DETECTION-BODY-3948))
  2: (SB-PRETTY::PPRINT-DEFPACKAGE #<SB-PRETTY:PRETTY-STREAM {10033C4991}> (DEFPACKAGE :SHEESH NIL))[:EXTERNAL]
  3: (SB-PRETTY:OUTPUT-PRETTY-OBJECT (DEFPACKAGE :SHEESH NIL) #<SB-IMPL::STRING-OUTPUT-STREAM {10033C4241}>)
  4: (SB-IMPL::STRINGIFY-OBJECT (DEFPACKAGE :SHEESH NIL))
  5: (PRIN1-TO-STRING (DEFPACKAGE :SHEESH NIL))

It seems that changing the (when a "a exists") to a (if a "a exists" t), fixes the problem. It seems that returning nil is a problem in this case. Returning true is fine.


I don't know if due to the specification, this is not an issue, however, extending defpackage, and even redefining it can be desirable in some situations such as developing a custom system definition suite.

Best,
Brent Millare