sexta-feira, 4 de janeiro de 2008

How to Mess with clos in subtle ways

The code below is wrong and stupid, but can generate very subtle bugs,especially if the class definition and de nstring-capitalize code aren't related

;; STEP 1: Define a class
(defclass foo ()
((xxx :initarg :xxx)))
(make-instance 'foo :xxx 1)

;; STEP 2: use nstring-capitalize in the keyword symbol
(nstring-capitalize (symbol-name :xxx))

;; STEP 3: try to make of instance of class
(make-instance 'foo :xxx 1)

The result is:

Invalid initialization argument: :XXX in call for class #.
[Condition of type SB-PCL::INITARG-ERROR]

See also:
Common Lisp Hyperspec, 7.1.2 [section]

0: (SB-PCL::CHECK-INITARGS-2-PLIST (:XXX 1) # (:|Xxx|) T)

According to

"symbol-name returns the name of symbol. The consequences are undefined if name is ever modified."

Shame on me.

Nenhum comentário: