Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Anonymous classes

25 views
Skip to first unread message

Ron Garret

unread,
Dec 3, 2008, 2:35:42 PM12/3/08
to
CLHS section 4.3.1 says:

"The name of an anonymous class is nil."

This implies that it is possible to create anonymous classes. How do
you do it? And having done it, is it possible to inherit from an
anonymous class? The DEFCLASS macro requires you to specify a name and
also requires that superclasses be specified by name. So how do you
make and use an anonymous class?

Thanks,
rg

Pascal Costanza

unread,
Dec 3, 2008, 2:42:28 PM12/3/08
to

Use the CLOS MOP:

(make-instance
'standard-class
:direct-slots ...
:direct-superclasses ...
...)

See the CLOS MOP specification for more details.


Pascal


--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/

Ron Garret

unread,
Dec 3, 2008, 3:29:10 PM12/3/08
to
In article <6po5p4F...@mid.individual.net>,
Pascal Costanza <p...@p-cos.net> wrote:

> Ron Garret wrote:
> > CLHS section 4.3.1 says:
> >
> > "The name of an anonymous class is nil."
> >
> > This implies that it is possible to create anonymous classes. How do
> > you do it? And having done it, is it possible to inherit from an
> > anonymous class? The DEFCLASS macro requires you to specify a name and
> > also requires that superclasses be specified by name. So how do you
> > make and use an anonymous class?
>
> Use the CLOS MOP:
>
> (make-instance
> 'standard-class
> :direct-slots ...
> :direct-superclasses ...
> ...)


I tried that and immediately encountered a series of problems:

? (make-instance (make-instance 'standard-class))
> Error: No applicable method for args:
> (#<error printing #<STANDARD-CLASS NIL> #x30004181C99D>)
> to #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x3000401BA85F>
> While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD (T)>, in process Listener(7).


? (allocate-instance (make-instance 'standard-class))
> Error: No applicable method for args:
> (#<error printing #<STANDARD-CLASS NIL> #x30004181BF5D> #<SYNONYM-STREAM to *TERMINAL-IO* #x3000416CFD4D>)
> to #<STANDARD-GENERIC-FUNCTION PRINT-OBJECT #x3000401C0DCF>
> While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD (T)>, in process Listener(7).


The MOP spec was very little help here because it doesn't actually seem
to describe the functionality of STANDARD-CLASS (or if it does I
couldn't find it). I would have expected STANDARD-CLASS to define
default methods for basic things like initialize-instance and
print-object, but apparently it doesn't, so I could use another hint.

Thanks,

rg

Matthew D Swank

unread,
Dec 3, 2008, 8:32:25 PM12/3/08
to
On Wed, 03 Dec 2008 12:29:10 -0800, Ron Garret wrote:

> In article <6po5p4F...@mid.individual.net>,
> Pascal Costanza <p...@p-cos.net> wrote:
>
>> Ron Garret wrote:
>> Use the CLOS MOP:
>>
>> (make-instance
>> 'standard-class
>> :direct-slots ...
>> :direct-superclasses ...
>> ...)
>
>
> I tried that and immediately encountered a series of problems:
>
> ? (make-instance (make-instance 'standard-class))
>> Error: No applicable method for args:
>> (#<error printing #<STANDARD-CLASS NIL> #x30004181C99D>) to
>> #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x3000401BA85F>
>> While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD
>> (T)>, in process Listener(7).
>
>
> ? (allocate-instance (make-instance 'standard-class))
>> Error: No applicable method for args:
>> (#<error printing #<STANDARD-CLASS NIL> #x30004181BF5D>
>> #<SYNONYM-STREAM to *TERMINAL-IO* #x3000416CFD4D>) to
>> #<STANDARD-GENERIC-FUNCTION PRINT-OBJECT #x3000401C0DCF>
>> While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD
>> (T)>, in process Listener(7).
>
>

You might have better luck bugging the clozure-cl guys. SBCL and CLisp
seem more amenable to creating instances of standard class.


Matt

--
Good day to let down old friends who need help.

Pascal Costanza

unread,
Dec 4, 2008, 3:55:47 AM12/4/08
to

It's one of those places which are not that well supported throughout
different CL implementations. But there are fixes for that in Closer to
MOP, because I rely heavily on such anonymous classes in ContextL. If
you use Closer to MOP, it should work in Clozure CL (but it may be that
i didn't cover all possible corner cases. I'm interested to hear about
your experiences.)

nikodemus

unread,
Dec 4, 2008, 4:44:30 AM12/4/08
to
On Dec 3, 10:29 pm, Ron Garret <rNOSPA...@flownet.com> wrote:

> ? (make-instance (make-instance 'standard-class))
>
> > Error: No applicable method for args:
> >         (#<error printing #<STANDARD-CLASS NIL> #x30004181C99D>)
> >         to #<STANDARD-GENERIC-FUNCTION INITIALIZE-INSTANCE #x3000401BA85F>
> > While executing: #<CCL::STANDARD-KERNEL-METHOD NO-APPLICABLE-METHOD (T)>, in process Listener(7).

> The MOP spec was very little help here because it doesn't actually seem


> to describe the functionality of STANDARD-CLASS (or if it does I
> couldn't find it). I would have expected STANDARD-CLASS to define
> default methods for basic things like initialize-instance and
> print-object, but apparently it doesn't, so I could use another hint.

What does CLASS-DIRECT-SUPERCLASSES return for (MAKE-INSTANCE
'STANDARD-CLASS)? Answer is NIL, so there cannot be an applicable
method on INITIALIZE-INSTANCE.

You might fare batter with this:

(make-instance
(make-instance 'standard-class
:direct-superclasses
(list (find-class 'standard-object))))

Cheers,

-- Nikodemus

Ron Garret

unread,
Dec 4, 2008, 3:34:17 PM12/4/08
to
In article <6ppk8iF...@mid.individual.net>,
Pascal Costanza <p...@p-cos.net> wrote:

I'll look into it. The CCL folks have acknowledged that this is a bug
in CCL and they're pretty good about fixing things.

rg

nikodemus

unread,
Dec 5, 2008, 8:48:53 AM12/5/08
to
On Dec 4, 11:44 am, nikodemus <nikodemus.siiv...@gmail.com> wrote:

> What does CLASS-DIRECT-SUPERCLASSES return for (MAKE-INSTANCE
> 'STANDARD-CLASS)? Answer is NIL, so there cannot be an applicable
> method on INITIALIZE-INSTANCE.

Just ignore me. As Gary rightly points out on the CCL mailing list,
AMOP says

"The class standard-object is the default direct superclass of the
class standard-class. When an instance of the class standard-class is
created, and no direct superclasses are explicitly specified, it
defaults to the class standard-object."

(SBCL had the same issue as CCL here, fixed in CVS.)

> Cheers,
>
>  -- Nikodemus

0 new messages