From: Mariano Montone
Subject: Slots metaobjects access through MOP
Date: 
Message-ID: <0fb7e643-1a48-4354-ba06-e5957949ea72@r32g2000vba.googlegroups.com>
Hi,
     I'd like to know how I can access an object slot metaobject from
outside slot-value-using-class. I mean, given an object instance and a
set of slot names, get the metaobjects, not the metaclass, of those
slots, to iterate over them, or bind them, for example.

Thanks

Mariano

From: Pascal J. Bourguignon
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <87iqp4z8r2.fsf@informatimago.com>
Mariano Montone <··············@gmail.com> writes:
>      I'd like to know how I can access an object slot metaobject from
> outside slot-value-using-class. I mean, given an object instance and a
> set of slot names, get the metaobjects, not the metaclass, of those
> slots, to iterate over them, or bind them, for example.

Yes. Have a look at: http://www.lisp.org/mop/index.html

However, perhaps you don't want that. Perhaps you just want to access
the slots by name: CLHS slot-value
http://www.lispworks.com/documentation/HyperSpec/Body/07_eb.htm

-- 
__Pascal Bourguignon__
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <18a637a7-75bd-4558-a23c-1d0da8d7ce39@v15g2000yqn.googlegroups.com>
On 28 dic, 12:15, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> Mariano Montone <··············@gmail.com> writes:
> >      I'd like to know how I can access an object slot metaobject from
> > outside slot-value-using-class. I mean, given an object instance and a
> > set of slot names, get the metaobjects, not the metaclass, of those
> > slots, to iterate over them, or bind them, for example.
>
> Yes. Have a look at:http://www.lisp.org/mop/index.html
>
> However, perhaps you don't want that. Perhaps you just want to access
> the slots by name: CLHS slot-valuehttp://www.lispworks.com/documentation/HyperSpec/Body/07_eb.htm

Sorry, but I can't find what I want. This is my problem. I have some
dataflow-slot-metaclass. Each dataflow-slot-metaclass defines a
listener slot. Then, I should be able to intercept the slot-value
setting with (setf slot-value-using-class) and iterate on the
listeners. That's ok, although I haven't tested it yet. But how can I,
given an object instance and a list of slots names, get those slot
metaobjects. The slot metaobjects are the ones that have the slot
listeners. My purpose is to implement a macro like (defmacro with-
dataflow-slots (slots object &rest body) ..) and bind the slot
metaobjects so that I can process the listeners of those slots.

If what I say is not understandable, it's ok. Maybe I should read the
MOP documentation more carefully.

Mariano
From: Kenny
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <4957cb31$0$20293$607ed4bc@cv.net>
Mariano Montone wrote:
> On 28 dic, 12:15, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
> 
>>Mariano Montone <··············@gmail.com> writes:
>>
>>>     I'd like to know how I can access an object slot metaobject from
>>>outside slot-value-using-class. I mean, given an object instance and a
>>>set of slot names, get the metaobjects, not the metaclass, of those
>>>slots, to iterate over them, or bind them, for example.
>>
>>Yes. Have a look at:http://www.lisp.org/mop/index.html
>>
>>However, perhaps you don't want that. Perhaps you just want to access
>>the slots by name: CLHS slot-valuehttp://www.lispworks.com/documentation/HyperSpec/Body/07_eb.htm
> 
> 
> Sorry, but I can't find what I want. This is my problem. I have some
> dataflow-slot-metaclass. Each dataflow-slot-metaclass defines a
> listener slot. Then, I should be able to intercept the slot-value
> setting with (setf slot-value-using-class) and iterate on the
> listeners. That's ok, although I haven't tested it yet.

I do not understand: you have managed to define a metaclass and arranged 
for custom slot definitions to be created and you cannot figure out how 
to get the slot definition associated with a slot name? That's weird, so 
maybe I do not understand you.

If I do understand you, there is no trick to it other than the fact that 
there is no built-in call.

First ask for the slots of the class (probably with class-slots on the 
class) and what you will get back (depending on which Lisp you use!) 
will be the effective-slot-definitions. Then just find the symbolic 
slot-name with a :key of slot-definition-name.

     (find 'my-slot (class-slots (find-class 'my-class))
        :key 'slot-definition-name)

hth,kenneth

ps.

> Maybe I should read the
> MOP documentation more carefully.

That was pretty tough sledding, as I recall. Don't be afraid to ask here.

pps. What Lisp are you using? The MOP varies from Lisp to Lisp. k
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <e31c3c59-9807-4032-8a63-6d17c1ccb490@h16g2000yqj.googlegroups.com>
On 28 dic, 16:53, Kenny <·········@gmail.com> wrote:
>
> > Maybe I should read the
> > MOP documentation more carefully.
>
> That was pretty tough sledding, as I recall. Don't be afraid to ask here.
>

Problem solved. I was confused about the meta levels. Thank you all
for your help. I'll post here when I'm stuck.

Off topic: Kenny, what I'm playing with has to do with what your Cells
library is for. I've worked in a project and relized that dataflow is
somewhat critical, or very desirable at least, for some applications.
Not that your library isn't useful. Just that, you know, writing code
is easier than reading it, although I should probably learn it because
its already mature and working. But there are several things I don't
totally understand yet. For example, how do you deal with dependencies
between objects and memory. How do you free the memory. Do you use
weak-references?

This is what I've come up with with my library:

(defclass bank-account ()
  ((money :initform (make-instance 'dfvaluecell :value 0))))

(defparameter *ba* (make-instance 'bank-account))

(defparameter *w*
  (let ((suma (let ((slot (slot-value *ba* 'money))
		    (b 2))
		(df
		 (declare (external b))
		 (+ slot b)))))
    (df
     (format t "Getting value of suma1!!~%")
     (* suma 5))))

The magic is in the df macro. It takes free variables and assumes they
are dfvaluecells, unless you declare they are external with (declare
(external )). Then, each free variable is bound through a weak-
reference, so memory management is automatic. The df transformed body
is added to those free variables as listener. The format is just for
debugging purposes.

Now I'm trying to plug things in CLOS so that valuecells are
transparent to CLOS users.

Mariano
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <7549652f-5ea3-4ab1-bdd1-1f84555546db@f18g2000vbf.googlegroups.com>
On 28 dic, 23:49, Mariano Montone <··············@gmail.com> wrote:
> On 28 dic, 16:53, Kenny <·········@gmail.com> wrote:
>
>
>
> > > Maybe I should read the
> > > MOP documentation more carefully.
>
> > That was pretty tough sledding, as I recall. Don't be afraid to ask here.
>
> Problem solved. I was confused about the meta levels. Thank you all
> for your help. I'll post here when I'm stuck.
>
> Off topic: Kenny, what I'm playing with has to do with what your Cells
> library is for. I've worked in a project and relized that dataflow is
> somewhat critical, or very desirable at least, for some applications.
> Not that your library isn't useful. Just that, you know, writing code
> is easier than reading it, although I should probably learn it because
> its already mature and working. But there are several things I don't
> totally understand yet. For example, how do you deal with dependencies
> between objects and memory. How do you free the memory. Do you use
> weak-references?
>
> This is what I've come up with with my library:
>
> (defclass bank-account ()
>   ((money :initform (make-instance 'dfvaluecell :value 0))))
>
> (defparameter *ba* (make-instance 'bank-account))
>
> (defparameter *w*
>   (let ((suma (let ((slot (slot-value *ba* 'money))
>                     (b 2))
>                 (df
>                  (declare (external b))
>                  (+ slot b)))))
>     (df
>      (format t "Getting value of suma1!!~%")
>      (* suma 5))))
>
> The magic is in the df macro. It takes free variables and assumes they
> are dfvaluecells, unless you declare they are external with (declare
> (external )). Then, each free variable is bound through a weak-
> reference, so memory management is automatic. The df transformed body
> is added to those free variables as listener. The format is just for
> debugging purposes.
>
> Now I'm trying to plug things in CLOS so that valuecells are
> transparent to CLOS users.
>
> Mariano

Of course, whenever I change the bank account money slot, *w* is
updated.
From: Kenny
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <49583adc$0$14274$607ed4bc@cv.net>
Mariano Montone wrote:
> On 28 dic, 16:53, Kenny <·········@gmail.com> wrote:
> 
>>>Maybe I should read the
>>>MOP documentation more carefully.
>>
>>That was pretty tough sledding, as I recall. Don't be afraid to ask here.
>>
> 
> 
> Problem solved. I was confused about the meta levels. Thank you all
> for your help. I'll post here when I'm stuck.
> 
> Off topic: Kenny, what I'm playing with has to do with what your Cells
> library is for. I've worked in a project and relized that dataflow is
> somewhat critical, or very desirable at least, for some applications.
> Not that your library isn't useful. Just that, you know, writing code
> is easier than reading it, although I should probably learn it because
> its already mature and working. But there are several things I don't
> totally understand yet. For example, how do you deal with dependencies
> between objects and memory. How do you free the memory. Do you use
> weak-references?

No, as a matter of fact I use Cells. Look at the "owning" parameter to 
the slot def... hang on. I forgot: you know Cells exists, you know where 
to find the source, you are not going to take the time to look at it, 
but you want me to spend time on explaining it.

I think you'll fit in pretty well around here!

kenneth
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <233eb8a4-dd4e-4121-96d7-5b142d5b3e03@n41g2000yqh.googlegroups.com>
On 29 dic, 00:50, Kenny <·········@gmail.com> wrote:
> Mariano Montone wrote:
> > On 28 dic, 16:53, Kenny <·········@gmail.com> wrote:
>
> >>>Maybe I should read the
> >>>MOP documentation more carefully.
>
> >>That was pretty tough sledding, as I recall. Don't be afraid to ask here.
>
> > Problem solved. I was confused about the meta levels. Thank you all
> > for your help. I'll post here when I'm stuck.
>
> > Off topic: Kenny, what I'm playing with has to do with what your Cells
> > library is for. I've worked in a project and relized that dataflow is
> > somewhat critical, or very desirable at least, for some applications.
> > Not that your library isn't useful. Just that, you know, writing code
> > is easier than reading it, although I should probably learn it because
> > its already mature and working. But there are several things I don't
> > totally understand yet. For example, how do you deal with dependencies
> > between objects and memory. How do you free the memory. Do you use
> > weak-references?
>
> No, as a matter of fact I use Cells. Look at the "owning" parameter to
> the slot def... hang on. I forgot: you know Cells exists, you know where
> to find the source, you are not going to take the time to look at it,
> but you want me to spend time on explaining it.
>
> I think you'll fit in pretty well around here!
>
> kenneth

haha  ok
From: Pascal J. Bourguignon
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <87d4fcz3j6.fsf@informatimago.com>
Mariano Montone <··············@gmail.com> writes:

> On 28 dic, 12:15, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> Mariano Montone <··············@gmail.com> writes:
>> > � � �I'd like to know how I can access an object slot metaobject from
>> > outside slot-value-using-class. I mean, given an object instance and a
>> > set of slot names, get the metaobjects, not the metaclass, of those
>> > slots, to iterate over them, or bind them, for example.
>>
>> Yes. Have a look at:http://www.lisp.org/mop/index.html
>>
>> However, perhaps you don't want that. Perhaps you just want to access
>> the slots by name: CLHS slot-valuehttp://www.lispworks.com/documentation/HyperSpec/Body/07_eb.htm
>
> Sorry, but I can't find what I want. This is my problem. I have some
> dataflow-slot-metaclass. Each dataflow-slot-metaclass defines a
> listener slot. Then, I should be able to intercept the slot-value
> setting with (setf slot-value-using-class) and iterate on the
> listeners. That's ok, although I haven't tested it yet. But how can I,
> given an object instance and a list of slots names, get those slot
> metaobjects. The slot metaobjects are the ones that have the slot
> listeners. My purpose is to implement a macro like (defmacro with-
> dataflow-slots (slots object &rest body) ..) and bind the slot
> metaobjects so that I can process the listeners of those slots.
>
> If what I say is not understandable, it's ok. Maybe I should read the
> MOP documentation more carefully.

I don't know what the "slot listeners" are.
http://www.lisp.org/mop/concepts.html mentions only:

  The following information is associated with both direct and effective slot definitions metaobjects:

      * The name, allocation, and type are available as forms that could
        appear in a defclass form.

      * The initialization form, if there is one, is available as a form
        that could appear in a defclass form. The initialization form
        together with its lexical environment is available as a function
        of no arguments which, when called, returns the result of
        evaluating the initialization form in its lexical
        environment. This is called the initfunction of the slot.

      * The slot filling initialization arguments are available as a list
        of symbols.

      * The documentation is available as a string or nil.

  Certain other information is only associated with direct slot definition
  metaobjects. This information applies only to the direct definition of
  the slot in the class (it is not inherited).

      * The function names of those generic functions for which there are
        automatically generated reader and writer methods. This
        information is available as lists of function names. Any accessors
        specified in the defclass form are broken down into their
        equivalent readers and writers in the direct slot definition. 


By "listener" do you mean "reader"?


-- 
__Pascal Bourguignon__
From: Alex Mizrahi
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <49578cf5$0$90265$14726298@news.sunsite.dk>
 MM>      I'd like to know how I can access an object slot metaobject from
 MM> outside slot-value-using-class. I mean, given an object instance and a
 MM> set of slot names, get the metaobjects, not the metaclass, of those
 MM> slots, to iterate over them, or bind them, for example.

if by "slot metaobject" you mean effective-slot-definitions then yes, you
can get them via CLASS-SLOTS function. like this:

(class-slots (find-class 'standard-generic-function))
(#<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::SOURCE>
 #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::PLIST>
 #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::%DOCUMENTATION>
 #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::INITIAL-METHODS>
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <05a33508-510b-4c57-af4e-36729ae7a7ea@e3g2000vbe.googlegroups.com>
On 28 dic, 12:28, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
>  MM>      I'd like to know how I can access an object slot metaobject from
>  MM> outside slot-value-using-class. I mean, given an object instance and a
>  MM> set of slot names, get the metaobjects, not the metaclass, of those
>  MM> slots, to iterate over them, or bind them, for example.
>
> if by "slot metaobject" you mean effective-slot-definitions then yes, you
> can get them via CLASS-SLOTS function. like this:
>
> (class-slots (find-class 'standard-generic-function))
> (#<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::SOURCE>
>  #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::PLIST>
>  #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::%DOCUMENTATION>
>  #<STANDARD-EFFECTIVE-SLOT-DEFINITION SB-PCL::INITIAL-METHODS>

Mmm...no...I don't want that. I would like something like: (slot-named
'lastname *person*) and that should give me the slot-definition with
the extra behavior and data I defined through a slot-metaclass for
that slot.

Mariano
From: Alex Mizrahi
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <49579ae3$0$90271$14726298@news.sunsite.dk>
 MM> Mmm...no...I don't want that. I would like something like: (slot-named
 MM> 'lastname *person*) and that should give me the slot-definition with
 MM> the extra behavior and data I defined through a slot-metaclass for
 MM> that slot.

first, let's clarify this, slot definitions are created for each _class_, 
not for
each object instance.

if you're looking for something that is associated with each instance,
 there is no ready-made machinery for this -- you'll have to make
your own.

if you really need a slot definition, there is no problem -- just
find them via class-slots. 
From: Mariano Montone
Subject: Re: Slots metaobjects access through MOP
Date: 
Message-ID: <344ff539-1833-4810-9ad6-67637d5f2ff5@v42g2000yqv.googlegroups.com>
On 28 dic, 13:27, "Alex Mizrahi" <········@users.sourceforge.net>
wrote:
>  MM> Mmm...no...I don't want that. I would like something like: (slot-named
>  MM> 'lastname *person*) and that should give me the slot-definition with
>  MM> the extra behavior and data I defined through a slot-metaclass for
>  MM> that slot.
>
> first, let's clarify this, slot definitions are created for each _class_,
> not for
> each object instance.
>
> if you're looking for something that is associated with each instance,
>  there is no ready-made machinery for this -- you'll have to make
> your own.
>
> if you really need a slot definition, there is no problem -- just
> find them via class-slots.

yeah...i see. I was mixing meta-levels.

Thanks!

Mariano