Article View: comp.lang.clos
Article #282clos initforms
From: Eric Peterson x7644
Date: Mon, 09 Nov 1992 15:49
Date: Mon, 09 Nov 1992 15:49
39 lines
1855 bytes
1855 bytes
Jeffrey> (defclass test-class ()
Jeffrey> ((slot-1 :initarg :slot-1
Jeffrey> :initform 1
Jeffrey> :accessor slot-1)
Jeffrey> (slot-2 :initarg :slot-2
Jeffrey> :initform ????? ; <- The question
Jeffrey> :accessor slot-2)))
Jeffrey> The problem is that I need for slot-2 to default to the same value as
Jeffrey> slot-1 if the user does not specify it in the constructor.
I believe the following will do what you want provided that you are
willing to call with :slot-2 first when both initargs are used (see
CLtL2 28.1.9.4. first paragraph after the last bullet):
(defclass test-class ()
((slot-1 :initarg :slot-1
:initform 1
:accessor slot-1)
(slot-2 :initarg :slot-1 :initarg :slot-2
:accessor slot-2)))
Required call order for non-defaulting case:
(make-instance 'test-clas :slot-2 5 :slot-1 3 )
I hope this helps.
Eric Peterson (speaking for myself)
Systems Research and Applications
2000 15th Street North
Arlington, VA 22201
USA
peterson@sra.com
(703) 558-7644
Fax: (703) 558-4723
Technical Details
Message-ID:
<9211091549.AA20508@verdi.iisd.sra.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sra.COM!petersonReferences:
<BxFov6.8J5@world.std.com>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos Path: arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sra.COM!peterson From: peterson@sra.COM (Eric Peterson x7644) Subject: clos initforms Message-ID: <9211091549.AA20508@verdi.iisd.sra.com> Sender: daemon@cis.ohio-state.edu Organization: The Ohio State University Department of Computer and Information Science References: <BxFov6.8J5@world.std.com> Date: Mon, 9 Nov 1992 15:49:58 GMT Lines: 40