defclass :initform behavior

David A. Thompson <[email protected]> Sun, 27 May 2012 17:49:04 -0700
Newsgroups gmane.emacs.eieio
Message-ID <20120528004904.5BC2E768C32@d630>
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@gm...> - 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)

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/