| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| This is a blatant help request - time is getting short ... I have methods that calculate coefficients. Object A has its method, object B, who is A's subclass inherits A. Now, the method specializing on B needs to call the method specializing on A, with its own arguments. So, I need to pass the list of arguments. But the first argument of A's method is the class. Do I have to specify it or will the whole method-combination machinery figure that out? If I need to specify it A's class, how do I identify it, knowing only B's class? Thanks for your help. Mirko |
|
#2
| |||
| |||
| Mirko.Vukovic@gmail.com wrote: > This is a blatant help request - time is getting short ... > > I have methods that calculate coefficients. Object A has its method, > object B, who is A's subclass inherits A. > > Now, the method specializing on B needs to call the method > specializing on A, with its own arguments. So, I need to pass the > list of arguments. But the first argument of A's method is the > class. Do I have to specify it or will the whole method-combination > machinery figure that out? > > If I need to specify it A's class, how do I identify it, knowing only > B's class? It's hard to follow your problem description, but here is what I get out of it: (defclass A () (...)) (defclass B (A) (...)) (defmethod m ((object A) x y) ...) (defmethod m ((object B) x y) ... (call-next-method object some-other-x some-other-y) ...) This works as expected, the method combination indeed figures out the right thing. This works because the list of applicable methods is determined based on the arguments you originally pass to a generic function. When invoking call-next-method with different arguments than the original ones, this list of applicable methods is not changed anymore. That's also why the HyperSpec says that if your new arguments are not compatible with the already known applicable methods that you will get undefined behavior. So there is no need to worry about having to pass something else as the first argument. It may be still be that I haven't understood your problem description well, but then you should provide more details. It always helps a lot to post some of the code involved, to better understand your problem. Pascal -- Lisp50: http://www.lisp50.org My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ |
|
#3
| |||
| |||
| Mirko.Vukovic@gmail.com wrote: > This is a blatant help request - time is getting short ... > > I have methods that calculate coefficients. Object A has its method, > object B, who is A's subclass inherits A. > > Now, the method specializing on B needs to call the method > specializing on A, with its own arguments. So, I need to pass the > list of arguments. But the first argument of A's method is the > class. Do I have to specify it or will the whole method-combination > machinery figure that out? > > If I need to specify it A's class, how do I identify it,... (find-class 'a) ![]() >.. knowing only > B's class? I'll give you some meta-help, or superhelp if you prefer: (apropos "SUPERCLASS") I'd tell you mine but it might be different from yours. The bad news is that the result will be named like a plural. If you only have one, (apropos "FIRST"). If you have multiples, try (apropos "RANDOM"). hth, kt |
|
#4
| |||
| |||
| On Oct 7, 11:27*am, Pascal Costanza <p...@p-cos.net> wrote: > Mirko.Vuko...@gmail.com wrote: > > This is a blatant help request - time is getting short ... > > > I have methods that calculate coefficients. *Object A has its method, > > object B, who is A's subclass inherits A. > > > Now, the method specializing on B needs to call the method > > specializing on A, with its own arguments. *So, I need to pass the > > list of arguments. *But the first argument of A's method is the > > class. *Do I have to specify it or will the whole method-combination > > machinery figure that out? > > > If I need to specify it A's class, how do I identify it, knowing only > > B's class? > > It's hard to follow your problem description, but here is what I get out > of it: > > (defclass A () (...)) > > (defclass B (A) (...)) > > (defmethod m ((object A) x y) > * *...) > > (defmethod m ((object B) x y) > * *... > * * * (call-next-method object some-other-x some-other-y) > * *...) > > This works as expected, the method combination indeed figures out the > right thing. > > This works because the list of applicable methods is determined based on > the arguments you originally pass to a generic function. When invoking > call-next-method with different arguments than the original ones, this > list of applicable methods is not changed anymore. That's also why the > HyperSpec says that if your new arguments are not compatible with the > already known applicable methods that you will get undefined behavior. > > So there is no need to worry about having to pass something else as the > first argument. > > It may be still be that I haven't understood your problem description > well, but then you should provide more details. It always helps a lot to > post some of the code involved, to better understand your problem. > > Pascal > > -- > Lisp50:http://www.lisp50.org > > My website:http://p-cos.net > Common Lisp Document Repository:http://cdr.eurolisp.org > Closer to MOP & ContextL:http://common-lisp.net/project/closer/ you explained it perfectly! thank you very much. Mirko |
|
#5
| |||
| |||
| Pascal Costanza wrote: > .... you will get undefined behavior. > > So there is no need to worry... What part of "undefined" are you not worrying about? kt |
|
#6
| |||
| |||
| Mirko.Vukovic@gmail.com wrote: > This is a blatant help request - time is getting short ... > > I have methods that calculate coefficients. Object A has its method, > object B, who is A's subclass inherits A. > > Now, the method specializing on B needs to call the method > specializing on A, with its own arguments. So, I need to pass the > list of arguments. But the first argument of A's method is the > class. Do I have to specify it or will the whole method-combination > machinery figure that out? > > If I need to specify it A's class, how do I identify it, knowing only > B's class? It just occurred to me that perhaps you did not mean it literally when you wrote that you wanted to pass the class as an argument. Your language above "..object B, who is A's subclass..." is definitely worrisome. You might take a moment to translate into actual runnable code, but I know time is short. If you are just simply trying to get a method specialized on a superclass to run you can do (call-next-method). But it seems you want to change other parameters as well. But you cannot invoke the method anew (I am guessing) because you will end up back in the same method and loop. If so, we had a chat here on this NG recently about these brave attempts to get more out of CLOS than is healthy. One now borders on the indeterminate dispatch of Prolog. Gosh, I wonder what code will run when? My classes are this, the methods are that, I'm calling call-next-method when this value is that but not this, the rules of precedence are ...hang on, lemme check... the class precedence is..oh my... Time is short, I suggest you add a new "do this" parameter to your method and beat the problem into submission: Just Tell the Computer what to do. Of course if time is /really/ short and the unsupported behavior is what you want, sure, ship it and buy Pascal a beer. hth, kt |
|
#7
| |||
| |||
| On Oct 7, 12:21*pm, Kenny <kentil...@gmail.com> wrote: > Mirko.Vuko...@gmail.com wrote: > > This is a blatant help request - time is getting short ... > > > I have methods that calculate coefficients. *Object A has its method, > > object B, who is A's subclass inherits A. > > > Now, the method specializing on B needs to call the method > > specializing on A, with its own arguments. *So, I need to pass the > > list of arguments. *But the first argument of A's method is the > > class. *Do I have to specify it or will the whole method-combination > > machinery figure that out? > > > If I need to specify it A's class, how do I identify it, knowing only > > B's class? > > It just occurred to me that perhaps you did not mean it literally when > you wrote that you wanted to pass the class as an argument. Your > language above "..object B, who is A's subclass..." is definitely > worrisome. You might take a moment to translate into actual runnable > code, but I know time is short. If you are just simply trying to get a > method specialized on a superclass to run you can do (call-next-method). > But it seems you want to change other parameters as well. But you cannot > invoke the method anew (I am guessing) because you will end up back in > the same method and loop. > > If so, we had a chat here on this NG recently about these brave attempts > to get more out of CLOS than is healthy. One now borders on the > indeterminate dispatch of Prolog. Gosh, I wonder what code will run > when? My classes are this, the methods are that, I'm calling > call-next-method when this value is that but not this, the rules of > precedence are ...hang on, lemme check... the class precedence is..oh my.... > > Time is short, I suggest you add a new "do this" parameter to your > method and beat the problem into submission: Just Tell the Computer what > to do. Of course if time is /really/ short and the unsupported behavior > is what you want, sure, ship it and buy Pascal a beer. > > hth, kt I admit, I felt really bad about that blatant help request. But my clos experience is still limited, and though I should have "just done it", I was felt that in case of an error, I would have no clue as where to go. As for beer. It is not just Pascal. There is that other Pascal, then you, and a couple of other folks that answered many of my own posted and unposted questions ... I owe you folks quite a lot. Thanks. Back to clos, what I need to do is by the CLOS book (and maybe the mop one since I'm at it). Mirko |
|
#8
| |||
| |||
| Kenny wrote: > Pascal Costanza wrote: >> .... you will get undefined behavior. >> >> So there is no need to worry... > > What part of "undefined" are you not worrying about? Those who can read have a clear advantage in life. Pascal -- Lisp50: http://www.lisp50.org My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ |
|
#9
| |||
| |||
| Pascal Costanza wrote: > Kenny wrote: > >> Pascal Costanza wrote: >> >>> .... you will get undefined behavior. >>> >>> So there is no need to worry... >> >> >> What part of "undefined" are you not worrying about? > > > Those who can read have a clear advantage in life. Sure, if you have trouble with... well, never mind, start reading about RDF, it is pushing CLOS into the sea: http://video.google.com/videoplay?do...22505157942928 hth,kt |
|
#10
| |||
| |||
| Kenny wrote: > Pascal Costanza wrote: >> Kenny wrote: >> >>> Pascal Costanza wrote: >>> >>>> .... you will get undefined behavior. >>>> >>>> So there is no need to worry... >>> >>> >>> What part of "undefined" are you not worrying about? >> >> >> Those who can read have a clear advantage in life. > > Sure, if you have trouble with... well, never mind, start reading about > RDF, it is pushing CLOS into the sea: > > http://video.google.com/videoplay?do...22505157942928 Ja, indeed, that video is a good example... Pascal -- Lisp50: http://www.lisp50.org My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP & ContextL: http://common-lisp.net/project/closer/ |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.