Opened 13 years ago

Closed 13 years ago

#119 closed defect (fixed)

Unexpected CLOS shared slot initialization order

Reported by: Mark Evenson Owned by: analysis
Priority: major Milestone: unscheduled
Component: CLOS Version: 1.0
Keywords: clos unexpected-behavior Cc:
Parent Tickets:


Didier Verner writes:

it seems that until now, I've been relying on a non-standard behavior,
namely the fact that shared slots with an :initform are initialized
before the first actual class instance is created:

(defclass test () ((slot :allocation :class :initform t)))

(defmethod initialize-instance :before ((test test) &key)
   (format t "Slot boundp: ~A~%" (slot-boundp test 'slot)))

CL-USER> (make-instance 'test)
Slot boundp: NIL
#<TEST {C5D3B8}>
CL-USER> (make-instance 'test)
Slot boundp: T
#<TEST {14563D4}>

I just fell on this because every other Common Lisp implementation I've
tried gives T and T here. Is it due to the way CLOS is implemented in
ABCL, and is there a chance that this can be improved?

Change History (3)

comment:1 Changed 13 years ago by Mark Evenson

Subject broached in comp.lang.lisp:

Side question: Is there a URI for comp.lang.lisp threads that doesn't go through the GOOG?

comment:2 Changed 13 years ago by ehuelsmann

Didier Verna follows up with:

So, after some discussion on cll and pro@, I have some precisions about
this. From what I understand of CLHS now, an implementation is not
required to initialize a shared slot at class creation time from the
initform (so far so good for ABCL).

However, the iniform of a shared slot must be evaluated in the dynamic
environment of the defclass call, even if it's not used to initialize
the slot right now (see the defclass page). The following test shows
that ABCL's behavior is currently incorrect in that regard:

(defclass fungy ()

((x :allocation :class

:initform (progn

(format *debug-io* "~&x initform~%")

:initarg :x)

(y :initform (progn

(format *debug-io* "~&y initform~%")

:initarg :y)))

CL-USER(1): (defclass fungy () ...)

CL-USER(2): (make-instance 'fungy)
x initform <========= this is too late
y initform
#<FUNGY {18C2354}>

comment:3 Changed 13 years ago by ehuelsmann

Resolution: fixed
Status: newclosed

(In [13185]) Fix #119: Incorrect dynamic environment for evaluation of :CLASS
allocation slot initforms.

Note: See TracTickets for help on using tickets.