EIEIO's DEFCLASS doesn't seem to handle :INITFORM in the same manner
as does Common Lisp CLOS. There does seem to have been some discussion
of this back in 2010 ('Constructor -- lambda expression' (From: Frank
<some.frank@......> - 2010-05-29 19:44)) on this list but the issue
doesn't seem to have been resolved.
Common Lisp specifies that the form provided to :INITFORM is evaluated
only at the time a new member of the class is generated:
CL-USER> (defvar x 0)
X
CL-USER> (setf x 0)
0
CL-USER> x
0
CL-USER> (defclass xyz ()
((name
:initarg :name
:initform (setf x (1+ x))
:type number)))
#<STANDARD-CLASS XYZ>
CL-USER> x
0
CL-USER>
Contrast this with EIEIO:
ELISP> (defvar x 0)
x
ELISP> (setf x 0)
0
ELISP> x
0
ELISP> (defclass xyz ()
((name
:initarg :name
:initform (setf x (1+ x))
:type number)))
xyz
ELISP> x
1
In EIEIO, DEFCLASS seems to evaluate the form passed to :INITFORM at
time of DEFCLASS invocation. Is this the intended behavior?
The EIEIO documents indicate, "The value passed to initform is
automatically quoted." Perhaps the documentation should be clarified
to be more explicit regarding whether the behavior of EIEIO is
intended to diverge from that of CLOS at this point.
Best wishes,
Alan
GNU Emacs 23.4.1 (debian emacs 23.4+1-3)
|