Posted by
Mark Miller on
Dec 28, 2019; 4:09am
URL: https://forum.world.st/Answering-a-question-Are-messages-objects-Running-into-a-problem-with-sendTo-tp5108912.html
I was trying to explain in a question on Smalltalk (on Quora.com) how
messages are also objects, and I'm running into a bit of a problem in trying
to demonstrate this in either Squeak or Pharo.
I started off using a simple example:
'5' asInteger --> 5
I can do the same thing with:
(Message selector: #asInteger) sendTo: '5' --> 5
This all works fine.
The response I got back from the person I was trying to convince was that
since I'm using syntax to create and send a message (using sendTo: with a
Message class), it's not really a message, because if a constructed message
with Message is a message, then why use syntax to send "sendTo:" to it? He
contends it's an object being used to represent a message. The actual
message gets sent in the process of evaluation (I suppose he thinks the
message is "unwrapped" from Message, and is sent under the covers).
I was going to try the following, to perhaps be more convincing (though I
don't know if this is a lost cause re. convincing), but I ran into a
problem. I tried translating the 2nd expression above into more explicit
terms, and I'm running into an exception I can't explain. To me, what I'm
doing is equivalent to the 2nd expression, but Smalltalk disagrees.
First version:
| m1 m2 |
m1 := Message selector: #asInteger.
m2 := Message selector: #sendTo argument: '5'.
m2 sendTo: m1.
I also tried the following:
(Message selector: #sendTo argument: '5') sendTo: (Message selector:
#asInteger)
In both cases, in both Squeak and Pharo, it throws up an exception saying:
"Message(Object)>>doesNotUnderstand: #sendTo" (Squeak)
or
"Instance of Message did not understand #sendTo" (Pharo).
This is bizarre to me, because if I look at Message in a browser, I can
clearly see sendTo: is an instance method. Also, if it wasn't an instance
method, then my very first example wouldn't have worked. I suspect I'm
running into some underlying mechanics of how messages are sent, and how
object state works in expressions.
Is this a bug? Am I missing something in how I'm using sendTo:? Or, does my
experimentation reveal that I'm wrong about messages? :)
Thanks in advance for any clarity on this.
---Mark
[hidden email]
--
Sent from:
http://forum.world.st/Squeak-Beginners-f107673.html_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners