Article View: comp.lang.clos
Article #284Re: clos initforms
From: George Williams
Date: Mon, 09 Nov 1992 05:18
Date: Mon, 09 Nov 1992 05:18
32 lines
1606 bytes
1606 bytes
On Nov 9, 3:49pm, Eric Peterson x7644 wrote: > 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 don't mean to start a flame war, but I sure wouldn't want to maintain this kind of code. --george
Technical Details
Message-ID:
<9211091718.AA05876@hsvaic.boeing.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!think.com!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!hsvaic.boeing.COM!georgeReferences:
george@hsvaic.boeing.COM (George Williams)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!hsvaic.boeing.COM!george From: george@hsvaic.boeing.COM (George Williams) Subject: Re: clos initforms Message-ID: <9211091718.AA05876@hsvaic.boeing.com> Sender: daemon@cis.ohio-state.edu Organization: The Ohio State University Department of Computer and Information Science References: george@hsvaic.boeing.COM (George Williams) Date: Mon, 9 Nov 1992 05:18:53 GMT Lines: 32