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

Slots metaobjects access through MOP

28 views
Skip to first unread message

Mariano Montone

unread,
Dec 28, 2008, 9:04:45 AM12/28/08
to
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

Pascal J. Bourguignon

unread,
Dec 28, 2008, 9:15:13 AM12/28/08
to

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__

Alex Mizrahi

unread,
Dec 28, 2008, 9:28:03 AM12/28/08
to
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>


Mariano Montone

unread,
Dec 28, 2008, 9:38:09 AM12/28/08
to
On 28 dic, 12:15, p...@informatimago.com (Pascal J. Bourguignon)
wrote:

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

Mariano Montone

unread,
Dec 28, 2008, 9:46:57 AM12/28/08
to
On 28 dic, 12:28, "Alex Mizrahi" <udode...@users.sourceforge.net>
wrote:

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

Alex Mizrahi

unread,
Dec 28, 2008, 10:27:29 AM12/28/08
to
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.


Mariano Montone

unread,
Dec 28, 2008, 10:56:49 AM12/28/08
to
On 28 dic, 13:27, "Alex Mizrahi" <udode...@users.sourceforge.net>
wrote:

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

Thanks!

Mariano

Pascal J. Bourguignon

unread,
Dec 28, 2008, 11:07:57 AM12/28/08
to

Mariano Montone <mariano...@gmail.com> writes:

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__

Message has been deleted

Kenny

unread,
Dec 28, 2008, 1:53:37 PM12/28/08
to
Mariano Montone wrote:
> On 28 dic, 12:15, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
>
>>Mariano Montone <marianomont...@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

Mariano Montone

unread,
Dec 28, 2008, 8:49:02 PM12/28/08
to
On 28 dic, 16:53, Kenny <kentil...@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

Mariano Montone

unread,
Dec 28, 2008, 8:51:09 PM12/28/08
to

Of course, whenever I change the bank account money slot, *w* is
updated.

Kenny

unread,
Dec 28, 2008, 9:50:04 PM12/28/08
to
Mariano Montone wrote:
> On 28 dic, 16:53, Kenny <kentil...@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

Mariano Montone

unread,
Dec 28, 2008, 10:16:34 PM12/28/08
to

haha ok

0 new messages