From: Mikalai
Subject: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <1143386847.769343.180600@e56g2000cwe.googlegroups.com>
Can you help me with the following CLOS problem.
I want to have a method that specializes on structures. More
importantly, on any structure (any thing of type, that has been created
by defstruct).
So,
(defmethod foo ((var ??what-should-be-here??)) ...)
and this method should be used on instances of (defstruct bar1 ...),
(defstruct bar2 ...), etc.
What I was able to find is that "all classes defined by means of
defstruct are instances of structure-class". But this a meta-class
stuff. Can this by useful in my problem? Is there other way to
solution?
Thanks in advance.

From: Mikalai
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <1143389466.518516.97870@v46g2000cwv.googlegroups.com>
Paul Foley wrote:
> On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
>
> > Can you help me with the following CLOS problem.
> > I want to have a method that specializes on structures. More
> > importantly, on any structure (any thing of type, that has been created
> > by defstruct).
> > So,
> > (defmethod foo ((var ??what-should-be-here??)) ...)
>
> The name of the struct, of course.

No-no. The point is that it should work for *any* structure. Possible
names are not known. All that is known is that these are structures.
From: Peter Seibel
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <m2ek0p18nu.fsf@gigamonkeys.com>
Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:

> On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
>
>> Can you help me with the following CLOS problem.
>> I want to have a method that specializes on structures. More
>> importantly, on any structure (any thing of type, that has been created
>> by defstruct).
>> So,
>> (defmethod foo ((var ??what-should-be-here??)) ...)
>
> The name of the struct, of course.

I think he wants a single method that handles all objects of types
created by DEFSTRUCT. Thus he wants:

  (defmethod foo ((var structure-class)) ...)

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Mikalai
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <1143390875.303867.303550@g10g2000cwb.googlegroups.com>
Peter Seibel wrote:
> Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:
>
> > On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
> >
> >> Can you help me with the following CLOS problem.
> >> I want to have a method that specializes on structures. More
> >> importantly, on any structure (any thing of type, that has been created
> >> by defstruct).
> >> So,
> >> (defmethod foo ((var ??what-should-be-here??)) ...)
> >
> > The name of the struct, of course.
>
> I think he wants a single method that handles all objects of types
> created by DEFSTRUCT. Thus he wants:
>
>   (defmethod foo ((var structure-class)) ...)
Except that this does not work.
In clisp:
[1]> (defstruct bar a b)
BAR
[2]> (setf a (make-instance 'bar))
#S(BAR :A NIL :B NIL)
[3]> (defmethod foo ((var structure-class)) "This is structure" )
#<STANDARD-METHOD (#<STRUCTURE-CLASS STRUCTURE-CLASS>)>
[4]> (foo a)

*** - NO-APPLICABLE-METHOD: When calling #<GENERIC-FUNCTION FOO> with
arguments(#S(BAR :A NIL :B NIL)), no method is applicable.
Break 1 [5]> :q

Or, am I missing something here?
From: Peter Seibel
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <m264m11655.fsf@gigamonkeys.com>
"Mikalai" <········@yahoo.com> writes:

> Peter Seibel wrote:
>> Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:
>>
>> > On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
>> >
>> >> Can you help me with the following CLOS problem.
>> >> I want to have a method that specializes on structures. More
>> >> importantly, on any structure (any thing of type, that has been created
>> >> by defstruct).
>> >> So,
>> >> (defmethod foo ((var ??what-should-be-here??)) ...)
>> >
>> > The name of the struct, of course.
>>
>> I think he wants a single method that handles all objects of types
>> created by DEFSTRUCT. Thus he wants:
>>
>>   (defmethod foo ((var structure-class)) ...)
> Except that this does not work.
> In clisp:
> [1]> (defstruct bar a b)
> BAR
> [2]> (setf a (make-instance 'bar))
> #S(BAR :A NIL :B NIL)
> [3]> (defmethod foo ((var structure-class)) "This is structure" )
> #<STANDARD-METHOD (#<STRUCTURE-CLASS STRUCTURE-CLASS>)>
> [4]> (foo a)
>
> *** - NO-APPLICABLE-METHOD: When calling #<GENERIC-FUNCTION FOO> with
> arguments(#S(BAR :A NIL :B NIL)), no method is applicable.
> Break 1 [5]> :q
>
> Or, am I missing something here?

No, I mixed up meta-levels, sorry. You want:

  (defmethod foo ((var structure-object) ...))

-Peter


-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: Pascal Costanza
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <48ntkkFkru15U1@individual.net>
Peter Seibel wrote:
> Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:
> 
> 
>>On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
>>
>>
>>>Can you help me with the following CLOS problem.
>>>I want to have a method that specializes on structures. More
>>>importantly, on any structure (any thing of type, that has been created
>>>by defstruct).
>>>So,
>>>(defmethod foo ((var ??what-should-be-here??)) ...)
>>
>>The name of the struct, of course.
> 
> 
> I think he wants a single method that handles all objects of types
> created by DEFSTRUCT. Thus he wants:
> 
>   (defmethod foo ((var structure-class)) ...)

No, he wants (defmethod foo ((var structure-object)) ...)

structure-class is the metaclass.

Pascal

-- 
3rd European Lisp Workshop
July 3-4 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
From: Mikalai
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <1143390997.743313.201990@v46g2000cwv.googlegroups.com>
Pascal Costanza wrote:
> Peter Seibel wrote:
> > Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:
> >
> >
> >>On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
> >>
> >>
> >>>Can you help me with the following CLOS problem.
> >>>I want to have a method that specializes on structures. More
> >>>importantly, on any structure (any thing of type, that has been created
> >>>by defstruct).
> >>>So,
> >>>(defmethod foo ((var ??what-should-be-here??)) ...)
> >>
> >>The name of the struct, of course.
> >
> >
> > I think he wants a single method that handles all objects of types
> > created by DEFSTRUCT. Thus he wants:
> >
> >   (defmethod foo ((var structure-class)) ...)
>
> No, he wants (defmethod foo ((var structure-object)) ...)
Thanks, it works:
[8]> (defmethod foo ((var structure-object)) "This is structure" )

WARNING:
The generic function #<GENERIC-FUNCTION FOO> is being modified, but has
alreadybeen called.
#<STANDARD-METHOD (#<STRUCTURE-CLASS STRUCTURE-OBJECT>)>
[9]> (foo a)
"This is structure"

Thank you guys :).
From: Pascal Bourguignon
Subject: Re: Help with CLOS -- specializer for structures - how?
Date: 
Message-ID: <87acbdf6k9.fsf@thalassa.informatimago.com>
"Mikalai" <········@yahoo.com> writes:

> Pascal Costanza wrote:
>> Peter Seibel wrote:
>> > Paul Foley <···@below.invalid> (http://public.xdi.org/=pf) writes:
>> >
>> >
>> >>On 26 Mar 2006 07:27:27 -0800, Mikalai  wrote:
>> >>
>> >>
>> >>>Can you help me with the following CLOS problem.
>> >>>I want to have a method that specializes on structures. More
>> >>>importantly, on any structure (any thing of type, that has been created
>> >>>by defstruct).
>> >>>So,
>> >>>(defmethod foo ((var ??what-should-be-here??)) ...)
>> >>
>> >>The name of the struct, of course.
>> >
>> >
>> > I think he wants a single method that handles all objects of types
>> > created by DEFSTRUCT. Thus he wants:
>> >
>> >   (defmethod foo ((var structure-class)) ...)
>>
>> No, he wants (defmethod foo ((var structure-object)) ...)
> Thanks, it works:
> [8]> (defmethod foo ((var structure-object)) "This is structure" )
>
> WARNING:
> The generic function #<GENERIC-FUNCTION FOO> is being modified, but has
> alreadybeen called.
> #<STANDARD-METHOD (#<STRUCTURE-CLASS STRUCTURE-OBJECT>)>
> [9]> (foo a)
> "This is structure"
>
> Thank you guys :).

Note however that defstruct can be used to metacreate lists and vectors too.


[1]> (defstruct (exl (:type list)) a b)
EXL
[2]> (make-exl :a 1 :b 2)
(1 2)
[3]> (defstruct (exv (:type vector)) a b)
EXV
[4]> (make-exv :a 1 :b 2)
#(1 2)
[5]> (defstruct exs a b)
EXS
[6]> (make-exs :a 1 :b 2)
#S(EXS :A 1 :B 2)
[7]> 

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Cats meow out of angst
"Thumbs! If only we had thumbs!
We could break so much!"