Discussion:
How does method lookup work exactly?
(too old to reply)
semtex
2011-01-31 10:05:10 UTC
Permalink
Hello!

I've read the blue book (pages 61 to 66 for that matter) but i still
have some question concerning the method lookup:

Situation:
Class Workstation has its superclass Object,
myWorkstation is a instance of Workstation.

if i do "myWorkstation createRandomFile: 400" what happens (let's
assume createRandomFile is defined in Workstation)?

Method lookup starts at the class of the instance that was called and
leads all the way up till "Object" =>

In my case, it starts at Workstation and then goes up to Object (if
needed). createRandomFile will be found in Workstation and the code
will be executed. so far so good.

but HOW can the method be found there? I thought you need a method
dictionary for that... and Behavior supplies that method dictionary.
But Workstation has no "Behavior" in his direct class hierarchy,
"Workstation class" has (and Workstation is a instance of Workstation
class..)

I'd highly appreciate it if someone could help me with that matter!

Thanks,
Klaus
Bruno
2011-01-31 13:07:29 UTC
Permalink
Post by semtex
but HOW can the method be found there? I thought you need a method
dictionary for that... and Behavior supplies that method dictionary.
But Workstation has no "Behavior" in his direct class hierarchy,
"Workstation class" has (and Workstation is a instance of Workstation
class..)
Each class has a Method Dictionary, where keys are the method name and
values are instances of CompiledMethod.

This can be different for differents Smalltalks.

Evaluate the following (in Dolphin Smalltalk):

Object methodDictionary
Object methodDictionary at: #printString

Regards,
Bruno
Matthias C. Buecker
2011-01-31 19:03:46 UTC
Permalink
Post by semtex
Hello!
I've read the blue book (pages 61 to 66 for that matter) but i still
Class Workstation has its superclass Object,
myWorkstation is a instance of Workstation.
if i do "myWorkstation createRandomFile: 400" what happens (let's
assume createRandomFile is defined in Workstation)?
Method lookup starts at the class of the instance that was called and
leads all the way up till "Object" =>
In my case, it starts at Workstation and then goes up to Object (if
needed). createRandomFile will be found in Workstation and the code
will be executed. so far so good.
but HOW can the method be found there? I thought you need a method
dictionary for that... and Behavior supplies that method dictionary.
But Workstation has no "Behavior" in his direct class hierarchy,
"Workstation class" has (and Workstation is a instance of Workstation
class..)
I'd highly appreciate it if someone could help me with that matter!
Thanks,
Klaus
I think you struggle with the following: a class is a metamodel of its
instances. Thus Workstation is a description of the instance
myWorkstation and the class Workstation is an instance of "Workstation
class". "Workstation class" is derived from Behavior which describes
that all if its instances will have a method dictionary. Therefore the
instance Workstation (of class "Workstation class") holds a method
dictionary ...

There you are ;-)
--
----------------------------------------------------------------------------
Dr. rer. pol. Matthias Bücker
Grißheimer Str. 13
D-79426 Buggingen
Tel. +49 7631 4607
mailTo:***@t-online.de
----------------------------------------------------------------------------
dmytro starosud
2011-02-19 21:13:06 UTC
Permalink
Hello,

Please, help me,
I'm interested of method looking:
the process of method looking may be controlled,
I mean can I bind some method in class,
that will be invoked when someone send a message to this class.
it can be:

MyClass on_message_send: message_args "this may contain dictionary of
selector parts and arguments or just one Symbol object etc."

when message is sent:

MyClass give: me some: sweets

automatically invokes method #on_message_send with argument (#give->me
#some->sweets)

thank you for your reply.
dmytro starosud
2011-02-19 21:17:32 UTC
Permalink
Hello,

Please, help me,
I'm interested of method looking:
may the process of method looking be controlled?
I mean can I bind some method in class,
that will be invoked when someone send a message to this class?
it can be something like that:

MyClass on_message_send: message_args "this may contain dictionary of
selector parts and arguments or just one Symbol object when message is
unary etc."

when message is sent:
(MyClass new) give: me some: sweets

automatically invokes method #on_message_send with argument:
(#give->me #some->sweets)

thank you for your reply.
Randal L. Schwartz
2011-02-20 14:28:11 UTC
Permalink
dmytro> may the process of method looking be controlled?

Look at implementors of #doesNotUnderstand: in your image for examples
of how to do this.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
dmytro starosud
2011-02-20 19:52:19 UTC
Permalink
Post by Randal L. Schwartz
Look at implementors of #doesNotUnderstand: in your image for examples
of how to do this.
sorry, but I can't find how to retrieve source code from an image
file.
there are a lot of unreadable data in it.

help me, please, do it,

thank you very much.
Steven Kelly
2011-02-21 10:08:06 UTC
Permalink
From your other message, I guess you're on GNU Smalltalk. You're probably
best asking your questions on their mailing list:
http://smalltalk.gnu.org/community

In general, source code doesn't live in the image file. Most Smalltalks have
a GUI IDE, and to access source code you use the IDE to look at classes, or
at senders or implementors of specific messages. If you're in a command-line
version of GNU Smalltalk, I don't know how you can inspect the source code.
The manual says this is a topic that might be documented later:
http://www.gnu.org/software/smalltalk/manual/gst.html#And-now
I'm sure someone in that community can help you.

All the best,
Steve

PS It sounds like you're quite new to Smalltalk. The questions you ask about
doesNotUnderstand: and evaluate: are moving into rather powerful features.
It's fine to use those powerful features, but there may be a better, easier
way. You might want to ask about the requirement you're facing, rather than
just how to implement one particular technical solution.
Post by dmytro starosud
Post by Randal L. Schwartz
Look at implementors of #doesNotUnderstand: in your image for examples
of how to do this.
sorry, but I can't find how to retrieve source code from an image
file.
there are a lot of unreadable data in it.
help me, please, do it,
thank you very much.
dmytro
2011-02-21 13:15:36 UTC
Permalink
Thanks a lot,
I will keep it it on my head.
John Brant
2011-02-21 14:22:07 UTC
Permalink
Post by dmytro starosud
Hello,
Please, help me,
may the process of method looking be controlled?
Generally method lookup is written in the VM so it isn't directly
controllable from Smalltalk. However, there are several ways to
indirectly control it. You may wish to look at my method wrappers paper:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.74.9328&rep=rep1&type=pdf

It has several different approaches for indirectly controlling method
lookup. I'm not familiar with GNU ST (which you appear to be using), but
most Smalltalks have support for the different approaches listed in the
paper.


John Brant

Loading...