HDTenEightyP/NetNews huggingface dataset:
From: peterson@sra.COM (Eric Peterson x7644)
Subject: Avoiding CLASS-PROTOTYPE (Attn: MOP gods)]
Organization: The Ohio State University Department of Computer and Information Science
Date: Thu, 5 Nov 1992 15:00:32 GMT

Hi Len;
   Some parens or better wording would have made my intent clearer; I
have added in parens -  *(* *)* - to clear up the ambiguity:

Since class instance prototypes have nothing but unbound slots, perhaps
the MOP should specify that class instance prototypes be created with
allocate-instance instead of using make-instance (as Lucid has done).

   Len> Lucid 4.0.2 *does* use MAKE-INSTANCE to create the class prototype. 

> (trace make-instance allocate-instance)
   Len> (MAKE-INSTANCE ALLOCATE-INSTANCE)
> (defclass test () ())
   Len> 1 Enter MAKE-INSTANCE #<Standard-Class STANDARD-CLASS>
   Len> | 2 Enter ALLOCATE-INSTANCE #<Standard-Class STANDARD-CLASS>
   Len> | 2 Exit ALLOCATE-INSTANCE #<Standard-Class #<Unbound-Slot 61A>>
   Len> 1 Exit MAKE-INSTANCE #<Standard-Class  #X1CE6F9E>
   Len> #<Standard-Class TEST>
> (clos:class-prototype *)
   Len> 1 Enter MAKE-INSTANCE #<Standard-Class TEST>
   Len> | 2 Enter ALLOCATE-INSTANCE #<Standard-Class TEST>
   Len> | 2 Exit ALLOCATE-INSTANCE #<Test #X1D03256>
   Len> 1 Exit MAKE-INSTANCE #<Test #X1D03256>
   Len> #<Test #X1D03256>

   Len> This behavior prevents me from writing the 'obvious' method for keeping class
   Len> prototype off of the instance list:

   Len> (defmethod make-instance :around ((class caching-class) &rest args)
   Len>   (let ((instance (call-next-method)))
   Len>     (unless (eq instance (clos:class-prototype class))
   Len>       (push instance (class-direct-instances class)))
   Len>     instance))

   Len> Because CLASS-PROTOTYPE and MAKE-INSTANCE are now mutually dependent, attempting
   Len> to make any instance of a class whose metaclass is CACHING-CLASS will cause an
   Len> infinite recursion.
   Len> ..................................................
   Len>                                   Len Charest, Jr.
   Len>                  JPL Artificial Intelligence Group
   Len>                           charest@aig.jpl.nasa.gov

Newsgroups: comp.lang.clos
From: charest@Aig.Jpl.Nasa.Gov (Len Charest)
Subject: Supplied-p in lambda-list (was Re: clos initforms'
Reply-To: charest@aig.jpl.nasa.gov
Organization: NASA/Jet Propulsion Laboratory
Date: Thu, 12 Nov 1992 01:10:33 GMT

In article <BxHA1I.G6D@world.std.com>, jbk@world.std.com (Jeffrey B Kane) writes:

|> ... I should define a constructor
|> function, then check if various key words have been defined, i.e.
|> 
|> (defclass test-class ()
|>   ((slot-1	:initarg :slot-1
|> 		:accessor slot-1)
|>    (slot-2	:initarg :slot-2
|> 		:accessor slot-2)))
|> 
|> (defun make-test-class (&key (slot-1 3) slot-2)
|>   (unless (boundp slot2)
|>     (setf slot-2 slot-1))
|>   (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))
|> 
|> Other than defining a keyword with some kind of a value to flag it
|> hasn't been used, how can you test if it was used similar to slot-boundp
|> for slots?

The lambda list of the function supports this kind of test. See page 76 of CLtL2.

(defun make-test-class (&key (slot-1 3) (slot-2 nil existp))
   (unless existp
     (setq slot-2 slot-1))
   (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))
..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          charest@aig.jpl.nasa.gov
From: matomira@disuns2.epfl.ch (Fernando Mato Mira)
Newsgroups: comp.lang.clos
Subject: CLOS Programming Methodology (was: CLOS shelf)
Date: 5 Nov 92 10:15:01 GMT
Reply-To: matomira@disuns2.epfl.ch (Fernando Mato Mira)
Organization: Ecole Polytechnique Federale de Lausanne

It would be good if we could come up with a set of guidelines for
producing good and reusable CLOS classes. Any personal experiences are
wellcome to the discussion. Reports on bugs using CLOS and packages on
different implementations will be helpful, too. 



-- 
Fernando D. Mato Mira
Computer Graphics Lab
Swiss Federal Institute of Technology
matomira@di.epfl.ch

NeXTMail : matomira@lignext.epfl.ch
FAX 	 : +41 (21) 693 - 5328
Newsgroups: comp.lang.clos
From: peterson@sra.COM (Eric Peterson x7644)
Subject: clos initforms
Organization: The Ohio State University Department of Computer and Information Science
Date: Mon, 9 Nov 1992 19:49:20 GMT

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

   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
From: peterson@sra.COM (Eric Peterson x7644)
Newsgroups: comp.lang.clos
Subject: class prototypes
Date: 6 Nov 92 16:23:08 GMT
Article-I.D.: verdi.9211061623.AA17684
Organization: The Ohio State University Department of Computer and Information Science

>>>>> On Fri, 6 Nov 92 11:06:49 EST, peterson said:

>>>>> On Thu, 5 Nov 1992 22:56:02 GMT, john@linus.mitre.org said:

   john> Still, is there anything in the MOP that proscribes a class prototype
   john> from being identical to a user-created instance, or to another class's
   john> prototype?

   peterson> Hi John;

   peterson>    Other that the requirement that a prototype be accessible by the
   peterson> generic function class-prototype, the AMOP MOP's silence on the
   peterson> subject seems to suggest free reign.  Have I missed a reference in
   peterson> there somewhere?


I neglected to mention that the prototype must be an instance of the
class; or at least that is how I interpret the following
class-prototype reader definition text:

"Returns a prototype instance of class." Ch. 5 (p. 77 if you
downloaded the free AMOP subset) under "Readers for Class Metaobjects".


                                   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
Newsgroups: comp.lang.clos
From: jbk@world.std.com (Jeffrey B Kane)
Subject: clos initforms
Summary: defining defaults in terms of one another
Keywords: INITFORM DEFAULT-INITARG INITIALIZE-INSTANCE
Organization: The World Public Access UNIX, Brookline, MA
Date: Mon, 9 Nov 1992 05:35:30 GMT

I was wondering if someone could suggest the best solution
for the following problem: 

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))

what I want is a generic way to have slot-2 = slot-1 in the first case and
slot-2 = 18 (the supplied value) in the second.  I'm looking for a general
enough solution so I don't have to do something like:

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

(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

===============
Jeffrey Kane, MD
Kane Biomedical Systems
Boston MA


Newsgroups: comp.lang.clos
From: kanderso@bbn.com
Subject: Re: clos initforms'
Organization: The Ohio State University Department of Computer and Information Science
Date: Tue, 10 Nov 1992 04:32:29 GMT

  To: comp.lang.clos@cis.ohio-state.edu
  Date: Tue, 10 Nov 1992 02:10:29 GMT
  Organization: The World Public Access UNIX, Brookline, MA
  From: Jeffrey B Kane <jbk@world.std.com>
  Sender: commonloops-request@cis.ohio-state.edu
  Subject: Re: clos initforms'
  
  >Try using an :after method for initialize-instance on this class.
  
  >E.g., (not tested),
  
  >(defmethod initialize-instance :after ((new test-class) &key)
  >  (unless (slot-boundp new 'slot-2)
  >    (setf (slot-2 new) (slot-1 new))))
  
While, i think the above is the right approach, for completeness, one could
also delay initializing slot-2 until it was accessed:

(defmethod slot-2 ((tc test-class))
 (if (slot-boundp tc 'slot-2) (slot-value tc 'slot-2)
     (if (slot-boundp tc 'slot-1) (setf (slot-value tc 'slot-2)
                                        (slot-value tc 'slot-1))
         (slot-value tc 'slot-2)))) ; Lose Lose.
  Dan,
  
  This would work, however after looking at the various ways that I
  should handle this, it looks like I should define a constructor
  function, then check if various key words have been defined, i.e.
  
  (defclass test-class ()
    ((slot-1	:initarg :slot-1
  		:accessor slot-1)
     (slot-2	:initarg :slot-2
  		:accessor slot-2)))
  
  (defun make-test-class (&key (slot-1 3) slot-2)
    (unless (boundp slot2)
      (setf slot-2 slot-1))
    (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))
  
  The problem with this approach is that the function "boundp"
  does not test if the user typed in a particular key word.
  
  Calling:
  
  (make-test-class :slot-2 4)
  
  results in the error:
  
  > Error: Unbound variable: SLOT2
  > While executing: SYMBOL-VALUE
  
  The reason I think that the constructor approach is bettter is than 
  using initialize-instance :after is that it allows other key word and
  a higher level of abstraction.  The the bottom line question is:
  
I really think using a constructor and an initialize-instance :after are
separate issues.  For example, your make-test-class constructor contains
knowledge about the class test-class.  If you now defined a class
test-class-2 as a subclass of test-class, and built the corresponding
constructor make-test-class-2, you would have to duplicate that knowledge.
Using initialize-instance :after, lets you specify that knowledge in one place.

So, i'd recommend using the initialize-instance :after approach to concentrate
knowledge about your classes in one place, and also the constructor
approach if you wanted to hide everything from your users.

  Other than defining a keyword with some kind of a value to flag it
  hasn't been used, how can you test if it was used similar to slot-boundp
  for slots?
  
(defun make-test-class (&key (slot-1 3) (slot-2 nil slot-2-bound-p)) ...
Newsgroups: comp.lang.clos
From: john@linus.mitre.org
Subject: class prototypes
Organization: The Ohio State University Department of Computer and Information Science
Date: Thu, 5 Nov 1992 22:56:02 GMT

Just to complicate things:

This discussion seems to assume that the class-prototype is NOT
identical to a user-created instance.  However, the first time
ALLOCATE-INSTANCE was called on a class, an implementation could cache
the result as the prototype, unless the prototype already existed (or
even if it did?).  This could even be done all the way up the
superclass chain, thus allowing some classes to have the SAME
prototype.  One (probably misguided) argument for this behavior would
be that it saves space.

Of course, the prototype is often (usually?) needed BEFORE the user
instantiates a class.  Worse, the user might change the class of the
cached instance, and the implementation would then have to recover.

Still, is there anything in the MOP that proscribes a class prototype
from being identical to a user-created instance, or to another class's
prototype?

John Burger
john@mitre.org
Newsgroups: comp.lang.clos
From: peterson@sra.COM (Eric Peterson x7644)
Subject: clos initforms
Organization: The Ohio State University Department of Computer and Information Science
Date: Mon, 9 Nov 1992 15:49:58 GMT

   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
From: peterson@sra.COM (Eric Peterson x7644)
Newsgroups: comp.lang.clos
Subject: class prototypes
Date: 6 Nov 92 16:07:22 GMT
Article-I.D.: verdi.9211061607.AA17648
Organization: The Ohio State University Department of Computer and Information Science

>>>>> On Thu, 5 Nov 1992 22:56:02 GMT, john@linus.mitre.org said:

   john> Still, is there anything in the MOP that proscribes a class prototype
   john> from being identical to a user-created instance, or to another class's
   john> prototype?

Hi John;

   Other that the requirement that a prototype be accessible by the
generic function class-prototype, the AMOP MOP's silence on the
subject seems to suggest free reign.  Have I missed a reference in
there somewhere?


-eric




                                   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
Newsgroups: comp.lang.clos
From: peterson@sra.COM (Eric Peterson x7644)
Subject: clos initforms
Organization: The Ohio State University Department of Computer and Information Science
Date: Mon, 9 Nov 1992 20:00:56 GMT

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

Newsgroups: comp.lang.clos
From: george@hsvaic.boeing.COM (George Williams)
Subject: Re: clos initforms
Organization: The Ohio State University Department of Computer and Information Science
Date: Mon, 9 Nov 1992 05:18:53 GMT

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
From: barmar@think.com (Barry Margolin)
Newsgroups: comp.lang.clos
Subject: Re: clos initforms'
Date: 10 Nov 1992 17:54:11 GMT
Organization: Thinking Machines Corporation, Cambridge MA, USA
NNTP-Posting-Host: telecaster.think.com

In article <BxHA1I.G6D@world.std.com> jbk@world.std.com (Jeffrey B Kane) writes:
>(defun make-test-class (&key (slot-1 3) slot-2)
>  (unless (boundp slot2)
>    (setf slot-2 slot-1))
>  (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))
>
>The problem with this approach is that the function "boundp"
>does not test if the user typed in a particular key word.
>
>Calling:
>
>(make-test-class :slot-2 4)
>
>results in the error:
>
>> Error: Unbound variable: SLOT2
>> While executing: SYMBOL-VALUE

The reason you got that error is because you mistyped the name of the
variable, leaving out the hyphen.  However, had you spelled it correctly
you would probably have gotten something like:

>>Error: The value of S, 4, should be a SYMBOL

BOUNDP:
   Required arg 0 (S): 4

The problem here is that you didn't quote the symbol argument to BOUNDP.

Fixing that, however, wouldn't solve your problem either.  BOUNDP can only
be used to test dynamic variables, not lexical variables; the latter are
always bound.  Also, the default value for unsupplied keyword arguments is
NIL, not unbound.

>Other than defining a keyword with some kind of a value to flag it
>hasn't been used, how can you test if it was used similar to slot-boundp
>for slots?

Use a supplied-p parameter (called "svar" on p.76-80 of CLtL2):

(defun make-test-class (&key (slot-1 3) (slot-2 nil slot-2-supplied-p))
  (unless slot-2-supplied-p
    (setf slot-2 slot-1))
  (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))

Also, the initform for optional and keyword parameters is evaluated in an
environment that includes the bindings of all the arguments preceding it in
the lambda list, so for this particular case you could write:

(defun make-test-class (&key (slot-1 3) (slot-2 slot-1))
  (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))
-- 
Barry Margolin
System Manager, Thinking Machines Corp.

barmar@think.com          {uunet,harvard}!think!barmar
Newsgroups: comp.lang.clos
From: charest@Aig.Jpl.Nasa.Gov (Len Charest)
Subject: Re: class prototypes
Reply-To: charest@aig.jpl.nasa.gov
Organization: NASA/Jet Propulsion Laboratory
Date: Sat, 7 Nov 1992 00:35:37 GMT

In article <9211052256.AA05389@thelonius.mitre.org>, john@linus.mitre.org writes:
|> Just to complicate things:

|> Still, is there anything in the MOP that proscribes a class prototype
|> from being identical to a user-created instance, or to another class's
|> prototype?

Interesting question. In my program I'm actually using the class-prototype to
access a *shared* slot (allocation :class). That is, I'm more interested in a
'CLASS-VOLUNTEER' than a prototype. This approach works, but should it?
My understanding is that 'the slots' of class-prototype remain uninitialized;
does this mean shared slots in a prototype are to be inaccessible or unbound?
..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          charest@aig.jpl.nasa.gov
From: jbk@world.std.com (Jeffrey B Kane)
Newsgroups: comp.lang.clos
Subject: Re: clos initforms'
Summary: boundp for keywords?
Date: 10 Nov 92 02:10:29 GMT
Article-I.D.: world.BxHA1I.G6D
Organization: The World Public Access UNIX, Brookline, MA

>Try using an :after method for initialize-instance on this class.

>E.g., (not tested),

>(defmethod initialize-instance :after ((new test-class) &key)
>  (unless (slot-boundp new 'slot-2)
>    (setf (slot-2 new) (slot-1 new))))

Dan,

This would work, however after looking at the various ways that I
should handle this, it looks like I should define a constructor
function, then check if various key words have been defined, i.e.

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

(defun make-test-class (&key (slot-1 3) slot-2)
  (unless (boundp slot2)
    (setf slot-2 slot-1))
  (make-instance 'test-class :slot-1 slot-1 :slot-2 slot-2))

The problem with this approach is that the function "boundp"
does not test if the user typed in a particular key word.

Calling:

(make-test-class :slot-2 4)

results in the error:

> Error: Unbound variable: SLOT2
> While executing: SYMBOL-VALUE

The reason I think that the constructor approach is bettter is than 
using initialize-instance :after is that it allows other key word and
a higher level of abstraction.  The the bottom line question is:

Other than defining a keyword with some kind of a value to flag it
hasn't been used, how can you test if it was used similar to slot-boundp
for slots?
     Jeffrey

================
Jeffrey Kane, MD
Kane Biomedical Systems

Internet jbk@world.std.com
Newsgroups: comp.lang.clos