From: Jim Newton
Subject: undefining a class
Date: 
Message-ID: <2hn3tfFf4gejU1@uni-berlin.de>
hi, does anyone know if there is a way to undefine a class?

From: Barry Margolin
Subject: Re: undefining a class
Date: 
Message-ID: <barmar-5E68F4.18060227052004@comcast.dca.giganews.com>
In article <··············@uni-berlin.de>, Jim Newton <·····@rdrop.com> 
wrote:

> hi, does anyone know if there is a way to undefine a class?

(setf (find-class 'class-name) nil)

will dissociate the class from the symbol, so that (make-instance 
'class-name) will stop working.  However, the class object will stay 
around as long as there are any instances of it or methods that refer to 
it in a specializer.

What is it you hope to accomplish by undefining the clas?

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Erann Gat
Subject: Re: undefining a class
Date: 
Message-ID: <gNOSPAMat-E95967.16013027052004@nntp1.jpl.nasa.gov>
In article <····························@comcast.dca.giganews.com>,
 Barry Margolin <······@alum.mit.edu> wrote:

> In article <··············@uni-berlin.de>, Jim Newton <·····@rdrop.com> 
> wrote:
> 
> > hi, does anyone know if there is a way to undefine a class?
> 
> (setf (find-class 'class-name) nil)

Find-class is setfable?!  Oh, the horror!

? (defclass foo () ())
#<STANDARD-CLASS FOO>
? (defclass baz () ())
#<STANDARD-CLASS BAZ>
? (setf (find-class 'foo) (find-class 'baz))
#<STANDARD-CLASS BAZ>
? (make-instance 'foo)
#<BAZ #xE01066>
? 

E.
From: Paul F. Dietz
Subject: Re: undefining a class
Date: 
Message-ID: <6rWdnVNdsOXYGSvdRVn-sA@dls.net>
Erann Gat wrote:
> In article <····························@comcast.dca.giganews.com>,
>  Barry Margolin <······@alum.mit.edu> wrote:
> 
> 
>>In article <··············@uni-berlin.de>, Jim Newton <·····@rdrop.com> 
>>wrote:
>>
>>
>>>hi, does anyone know if there is a way to undefine a class?
>>
>>(setf (find-class 'class-name) nil)
> 
> 
> Find-class is setfable?!  Oh, the horror!

As is class-name.  There are some subtleties involved with 'proper classes'
(see 4.3.1) that tripped up some implementations when tests for this were
added to ansi-tests.

	Paul
From: Steven M. Haflich
Subject: Re: undefining a class
Date: 
Message-ID: <OrAtc.73709$A43.25524@newssvr25.news.prodigy.com>
Barry Margolin wrote:

>>hi, does anyone know if there is a way to undefine a class?
> 
> (setf (find-class 'class-name) nil)
> 
> will dissociate the class from the symbol, so that (make-instance 
> 'class-name) will stop working.  However, the class object will stay 
> around as long as there are any instances of it or methods that refer to 
> it in a specializer.

Or while there exist classes that refer to it as sub- or super-classes,
or any other reference.  Since any standard-class, once defined, will
be a direct or transitively-indirect subclass of standard-object, it
follows that a class can never be undefined (i.e. garbage collected).
The class may be moved around and reparented when it is reinitialized
(see add-direct-subclass and remove-direct-subclass) but I can't think
of any way to prevent a class from being the direct subclassof at least
ine class such as standard-object in the class lattice.

Classes are first class objects in Common Lisp.  _Usually_ we refer to
classes by names because that is convenient and readable, but the
metaobject protocol exists in part so that class objects can be
manipulated as objects.  For example:

  (setq class
    (mop:ensure-class nil
		     :direct-superclasses (list (find-class 'standard-object))))
  ==> #<standard-class nil>
  (make-instance class)
  ==> #<nil @ #x7281d5ca>
From: Pascal Costanza
Subject: Re: undefining a class
Date: 
Message-ID: <c96vjb$qo$1@newsreader2.netcologne.de>
Steven M. Haflich wrote:

> Barry Margolin wrote:
> 
>>> hi, does anyone know if there is a way to undefine a class?
>>
>> (setf (find-class 'class-name) nil)
>>
>> will dissociate the class from the symbol, so that (make-instance 
>> 'class-name) will stop working.  However, the class object will stay 
>> around as long as there are any instances of it or methods that refer 
>> to it in a specializer.
> 
> Or while there exist classes that refer to it as sub- or super-classes,
> or any other reference.  Since any standard-class, once defined, will
> be a direct or transitively-indirect subclass of standard-object, it
> follows that a class can never be undefined (i.e. garbage collected).
> The class may be moved around and reparented when it is reinitialized
> (see add-direct-subclass and remove-direct-subclass) but I can't think
> of any way to prevent a class from being the direct subclassof at least
> ine class such as standard-object in the class lattice.

I have some code in which I know that certain classes are leaves, I know 
about all the methods that are specialized to them, and I know that 
there are no instances of those classes. The code that unlinks such a 
class, apart from moving the respective methods from their generic 
functions, looks roughly like this:

(dolist (superclass (class-direct-superclasses class))
   (remove-direct-subclass superclass class))

I am convinced that this should work. Or am I missing something?


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: Jim Newton
Subject: Re: undefining a class
Date: 
Message-ID: <2hr9cdFeghouU1@uni-berlin.de>
The reason I ask in the first place?
because i work a lot with a LISP dialect which supports
classes and somewhat limited generic functions.  However,
the language does not support packages or name spaces.
Therefore if anyone's program/file defines a class, it is
therefore visible to all of VM.   We normally handle
this by asking everyone to obey a naming convention which
works very well but is far from perfect.

We can undefine functions with (putd 'funname nil) and
undefine variables with (setq variable 'unbound).
but classes which are often global data are not
undefineable.

If there were a way in common lisp to do this, it would
make since to model after that.  But there does not
seem to be a way in common lisp, as it is probably not
needed when you are using packages.

-jim

Pascal Costanza wrote:
> 
> Steven M. Haflich wrote:
> 
>> Barry Margolin wrote:
>>
>>>> hi, does anyone know if there is a way to undefine a class?
>>>
>>>
>>> (setf (find-class 'class-name) nil)
>>>
>>> will dissociate the class from the symbol, so that (make-instance 
>>> 'class-name) will stop working.  However, the class object will stay 
>>> around as long as there are any instances of it or methods that refer 
>>> to it in a specializer.
>>
>>
>> Or while there exist classes that refer to it as sub- or super-classes,
>> or any other reference.  Since any standard-class, once defined, will
>> be a direct or transitively-indirect subclass of standard-object, it
>> follows that a class can never be undefined (i.e. garbage collected).
>> The class may be moved around and reparented when it is reinitialized
>> (see add-direct-subclass and remove-direct-subclass) but I can't think
>> of any way to prevent a class from being the direct subclassof at least
>> ine class such as standard-object in the class lattice.
> 
> 
> I have some code in which I know that certain classes are leaves, I know 
> about all the methods that are specialized to them, and I know that 
> there are no instances of those classes. The code that unlinks such a 
> class, apart from moving the respective methods from their generic 
> functions, looks roughly like this:
> 
> (dolist (superclass (class-direct-superclasses class))
>   (remove-direct-subclass superclass class))
> 
> I am convinced that this should work. Or am I missing something?
> 
> 
> Pascal
> 
From: John Thingstad
Subject: Re: undefining a class
Date: 
Message-ID: <opr8rfgxbtpqzri1@mjolner.upc.no>
What not take the bull by the horns and define defpackage.
Source is available in cmucl for example and it should be a
simple mater to port it.

On Sat, 29 May 2004 12:15:22 +0200, Jim Newton <·····@rdrop.com> wrote:

> The reason I ask in the first place?
> because i work a lot with a LISP dialect which supports
> classes and somewhat limited generic functions.  However,
> the language does not support packages or name spaces.
> Therefore if anyone's program/file defines a class, it is
> therefore visible to all of VM.   We normally handle
> this by asking everyone to obey a naming convention which
> works very well but is far from perfect.
>
> We can undefine functions with (putd 'funname nil) and
> undefine variables with (setq variable 'unbound).
> but classes which are often global data are not
> undefineable.
>
> If there were a way in common lisp to do this, it would
> make since to model after that.  But there does not
> seem to be a way in common lisp, as it is probably not
> needed when you are using packages.
>
> -jim
>
> Pascal Costanza wrote:
>>  Steven M. Haflich wrote:
>>
>>> Barry Margolin wrote:
>>>
>>>>> hi, does anyone know if there is a way to undefine a class?
>>>>
>>>>
>>>> (setf (find-class 'class-name) nil)
>>>>
>>>> will dissociate the class from the symbol, so that (make-instance  
>>>> 'class-name) will stop working.  However, the class object will stay  
>>>> around as long as there are any instances of it or methods that refer  
>>>> to it in a specializer.
>>>
>>>
>>> Or while there exist classes that refer to it as sub- or super-classes,
>>> or any other reference.  Since any standard-class, once defined, will
>>> be a direct or transitively-indirect subclass of standard-object, it
>>> follows that a class can never be undefined (i.e. garbage collected).
>>> The class may be moved around and reparented when it is reinitialized
>>> (see add-direct-subclass and remove-direct-subclass) but I can't think
>>> of any way to prevent a class from being the direct subclassof at least
>>> ine class such as standard-object in the class lattice.
>>   I have some code in which I know that certain classes are leaves, I  
>> know about all the methods that are specialized to them, and I know  
>> that there are no instances of those classes. The code that unlinks  
>> such a class, apart from moving the respective methods from their  
>> generic functions, looks roughly like this:
>>  (dolist (superclass (class-direct-superclasses class))
>>   (remove-direct-subclass superclass class))
>>  I am convinced that this should work. Or am I missing something?
>>   Pascal
>>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
From: Pascal Costanza
Subject: Re: undefining a class
Date: 
Message-ID: <c9a14l$60c$1@newsreader2.netcologne.de>
Jim Newton wrote:

> The reason I ask in the first place?
> because i work a lot with a LISP dialect which supports
> classes and somewhat limited generic functions.  However,
> the language does not support packages or name spaces.
> Therefore if anyone's program/file defines a class, it is
> therefore visible to all of VM.   We normally handle
> this by asking everyone to obey a naming convention which
> works very well but is far from perfect.
> 
> We can undefine functions with (putd 'funname nil) and
> undefine variables with (setq variable 'unbound).
> but classes which are often global data are not
> undefineable.
> 
> If there were a way in common lisp to do this, it would
> make since to model after that.  But there does not
> seem to be a way in common lisp, as it is probably not
> needed when you are using packages.

Common Lisp provides makunbound and fmakunbound to unbind variables and 
functions. It would be better (i.e., more portable) to write these 
functions and then say (makunbound 'vname) and (fmakunbound 'fname). If 
you don't want to integrate a package system, it's probably a good idea 
to write a similar function cmakunbound (or perhaps unbind-class) to do 
the same thing for classes. If you ever have the need to port to Common 
Lisp (or other Lisp dialects), it's then easier to spot the places where 
you need this functionality.

AFAICS, the use case you describe is not directly supported by Common Lisp.


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: Rahul Jain
Subject: Re: undefining a class
Date: 
Message-ID: <87y8n6o5ui.fsf@nyct.net>
Jim Newton <·····@rdrop.com> writes:

> We can [...] undefine variables with (setq variable 'unbound).

Huh? Wouldn't that set the variable to the symbol named "UNBOUND"? Does
this language forbid the use of a symbol with name "UNBOUND"? Would you
get undefined variable errors if you did:
(defmacro foo (x)
  `(... ,x ...))
(foo unbound)
?

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist
From: Pascal Costanza
Subject: Re: undefining a class
Date: 
Message-ID: <c95nr2$ioa$1@newsreader2.netcologne.de>
Jim Newton wrote:
> hi, does anyone know if there is a way to undefine a class?

During development, (unintern 'my-class) is just fine. For a running 
program, this is too crude, especially when you want to do it often.

ANSI CL specifies that you can remove a class association by calling 
(setf (find-class 'my-class) nil). However, you probably also need to 
call remove-direct-subclass for each superclass accordingly - see the 
MOP specification - in order to ensure that the class metaobject can be 
garbage collected.


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/
From: Erann Gat
Subject: Re: undefining a class
Date: 
Message-ID: <gNOSPAMat-F3A63A.15293827052004@nntp1.jpl.nasa.gov>
In article <············@newsreader2.netcologne.de>,
 Pascal Costanza <········@web.de> wrote:

> Jim Newton wrote:
> > hi, does anyone know if there is a way to undefine a class?
> 
> During development, (unintern 'my-class) is just fine.

That may or may not do what the OP wants.  Consider:

? (defclass foo () ())
#<STANDARD-CLASS FOO>
? (setf foosym 'foo)
FOO
? (setf fooclass (find-class 'foo))
#<STANDARD-CLASS FOO>
? (unintern 'foo)
T
? (make-instance foosym)
#<#:FOO #xDFC05E>
? (make-instance fooclass)
#<#:FOO #xDFC43E>
? 

Just because a symbol is uninterned doesn't mean it's gone.

What does it mean to undefine a class?  What do you want to happen to 
existing instances of the class?

E.
From: Pascal Costanza
Subject: Re: undefining a class
Date: 
Message-ID: <c961n0$6ds$1@newsreader2.netcologne.de>
Erann Gat wrote:

> In article <············@newsreader2.netcologne.de>,
>  Pascal Costanza <········@web.de> wrote:
> 
> 
>>Jim Newton wrote:
>>
>>>hi, does anyone know if there is a way to undefine a class?
>>
>>During development, (unintern 'my-class) is just fine.
> 
> That may or may not do what the OP wants.  Consider:
> 
> ? (defclass foo () ())
> #<STANDARD-CLASS FOO>
> ? (setf foosym 'foo)
> FOO
> ? (setf fooclass (find-class 'foo))
> #<STANDARD-CLASS FOO>
> ? (unintern 'foo)
> T
> ? (make-instance foosym)
> #<#:FOO #xDFC05E>
> ? (make-instance fooclass)
> #<#:FOO #xDFC43E>
> ? 
> 
> Just because a symbol is uninterned doesn't mean it's gone.

Yes, but your example is unusual, isn't it? ;)


Pascal

-- 
1st European Lisp and Scheme Workshop
June 13 - Oslo, Norway - co-located with ECOOP 2004
http://www.cs.uni-bonn.de/~costanza/lisp-ecoop/