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.
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.
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:
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.
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.
On 28 dic, 12:28, "Alex Mizrahi" <udode...@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:
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.
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.
On 28 dic, 13:27, "Alex Mizrahi" <udode...@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.
Mariano Montone <marianomont...@gmail.com> writes: > 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.
> 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.
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.
>>> 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.
> 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.
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?
(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.
> 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?
> 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.
>>>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.
> >>>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.