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
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 ...
...)
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/
In article <··············@mid.individual.net>,
Pascal Costanza <··@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
On Wed, 03 Dec 2008 12:29:10 -0800, Ron Garret wrote:
> In article <··············@mid.individual.net>,
> Pascal Costanza <··@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.
Matthew D Swank wrote:
> On Wed, 03 Dec 2008 12:29:10 -0800, Ron Garret wrote:
>
>> In article <··············@mid.individual.net>,
>> Pascal Costanza <··@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.
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.)
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/
In article <··············@mid.individual.net>,
Pascal Costanza <··@p-cos.net> wrote:
> Matthew D Swank wrote:
> > On Wed, 03 Dec 2008 12:29:10 -0800, Ron Garret wrote:
> >
> >> In article <··············@mid.individual.net>,
> >> Pascal Costanza <··@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.
>
> 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.)
>
> Pascal
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
On Dec 3, 10:29 pm, Ron Garret <·········@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
On Dec 4, 11:44 am, nikodemus <·················@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