🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.clos
Article #291

Re: clos initforms

#291
From: Russell G. Almond
Date: Tue, 10 Nov 1992 20:15
39 lines
1738 bytes
Jeffery Asks:

> (defun make-test-class ((me test-class) &key (:slot-1 1) (:slot-2 nil))
> 	(unless slot-2
> 		(setf slot-2 slot1)) ; if no default value for slot-2 use 
>                                    ; slot-1's value
> 	(make-instance 'test-class :slot-1 slot-1 :slot-2 slot2))

> The problem I see with this approach is that it does not let you specify a nil 
> value for
> slot-2.  What I'm looking for is a general solution that doesn't lock out some 
> previously
> defined "bad" value (nil in the above example).

>     Jeffrey


I think you want the third (suppliedp) argument for &key (and &optional)
parameters in a lambda list.  Thus:

(defun make-test-class ((me test-class) &key (:slot-1 1)
                                             (:slot-2 nil slot-2?))
	(unless slot-2?
		(setf slot-2 slot1)) ; if no default value for slot-2 use 
				     ; slot-1's value
	(make-instance 'test-class :slot-1 slot-1 :slot-2 slot2))

This should do what you want.  (There should be an equivalent way to to
it with a shared-initalize method, I'm not as familiar with that
approach.)


			Russell Almond			   
Statistical Sciences, Inc.		
1700 Westlake Ave., N Suite 500		
Seattle, WA  98109			
(206) 283-8802				
almond@statsci.com			
Technical Details
Message-ID: <ALMOND.92Nov10121555@bass.statsci.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!statsci!almond
References: <BxFov6.8J5@world.std.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.clos
Path: arc1-ca.pugleaf.net!sparky!uunet!statsci!almond
From: almond@statsci.com (Russell G. Almond)
Subject: Re: clos initforms
In-Reply-To: jbk@world.std.com's message of 9 Nov 92 05:35:30 GMT
Message-ID: <ALMOND.92Nov10121555@bass.statsci.com>
Sender: usenet@statsci.com (Usenet News Account)
Organization: Statistical Sciences, Inc., Seattle, WA USA
References: <BxFov6.8J5@world.std.com>
Date: Tue, 10 Nov 1992 20:15:55 GMT
Lines: 40