Article View: comp.lang.clos
Article #283Re: clos initforms
From: Jose E. Hernandez
Date: Mon, 09 Nov 1992 16:43
Date: Mon, 09 Nov 1992 16:43
39 lines
1650 bytes
1650 bytes
|> I have a class with several slots As an example:
|>
|> (defclass test-class ()
|> ((slot-1 :initarg :slot-1
|> :initform 1
|> :accessor slot-1)
|> (slot-2 :initarg :slot-2
|> :initform ????? ; <- The question
|> :accessor slot-2)))
|>
|> The problem is that I need for slot-2 to default to the same value as
|> slot-1 if the user does not specify it in the constructor.
|>
|> (setf my-class-1 (make-instance 'test-class :slot-1 12))
|>
|> (setf my-class-2 (make-instance 'test-class :slot-1 12 :slot-2 18))
|>
|> Jeffrey Kane, MD
|> Kane Biomedical Systems
|> Boston MA
(defparameter *default-test-class-slot-value* 1)
(defclass test-class ()
((slot-1 :initarg :slot-1
:initform *default-test-class-slot-value*
:accessor slot-1)
(slot-2 :initarg :slot-2
:initform *default-test-class-slot-value*
:accessor slot-2)))
(defmethod shared-initialize ((inst test-class) slots &rest initargs
&key slot-1 slot-2)
(if (and slot-1 (not slot-2))
(apply #'call-next-method inst slots :slot-2 slot-1 initargs)
(call-next-method)))
jeh
Technical Details
Message-ID:
<141013@lll-winken.LLNL.GOV>Path:
arc1-ca.pugleaf.net!sparky!uunet!portal!lll-winken!windrider.llnl.gov!jehReferences:
<BxFov6.8J5@world.std.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!portal!lll-winken!windrider.llnl.gov!jeh From: jeh@windrider.llnl.gov (Jose E. Hernandez) Newsgroups: comp.lang.clos Subject: Re: clos initforms Keywords: INITFORM DEFAULT-INITARG INITIALIZE-INSTANCE Message-ID: <141013@lll-winken.LLNL.GOV> Date: 9 Nov 92 16:43:41 GMT References: <BxFov6.8J5@world.std.com> Sender: usenet@lll-winken.LLNL.GOV Reply-To: jeh@llnl.gov Organization: Lawrence Livermore National Laboratory Lines: 39 Nntp-Posting-Host: windrider.llnl.gov