🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #286

clos initforms

#286
From: Eric Peterson x7644
Date: Mon, 09 Nov 1992 20:00
51 lines
2403 bytes
Sorry about the previous garbage message.  My ^C has a hair trigger.

>>>>> On Mon, 9 Nov 1992 05:18:53 GMT, george@hsvaic.boeing.COM (George Williams) said:

   George> 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.

   Eric> I believe the following will do what you want provided that you are
   Eric> willing to call with :slot-2 first when both initargs are used (see
   Eric> CLtL2 28.1.9.4. first paragraph after the last bullet):

   Eric> (defclass test-class ()
   Eric> ((slot-1 :initarg :slot-1
   Eric> :initform 1
   Eric> :accessor slot-1)
   Eric> (slot-2 :initarg :slot-1 :initarg :slot-2 
   Eric> :accessor slot-2)))


   Eric> Required call order for non-defaulting case:

   Eric> (make-instance 'test-clas :slot-2 5 :slot-1 3 )

   George> I don't mean to start a flame war, but I sure wouldn't want to maintain
   George> this kind of code.

   George> --george

I'm not crazy about it either; but I'm also not crazy about the verbose
alternatives.  A good solution would require some MOP magic.




                                   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: <9211092000.AA21112@verdi.iisd.sra.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sra.COM!peterson
References: <9211091718.AA05876@hsvaic.boeing.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos
Path: arc1-ca.pugleaf.net!sparky!uunet!ukma!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!sra.COM!peterson
From: peterson@sra.COM (Eric Peterson x7644)
Subject: clos initforms
Message-ID: <9211092000.AA21112@verdi.iisd.sra.com>
Sender: daemon@cis.ohio-state.edu
Organization: The Ohio State University Department of Computer and Information Science
References: <9211091718.AA05876@hsvaic.boeing.com>
Date: Mon, 9 Nov 1992 20:00:56 GMT
Lines: 52