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 |
One thing I guess I should clarify is that when I inspected local bindings in
the expression that caused the exception, I found that the rightmost entity in my submitted expression (created by (Message selector: #asInteger)) didn't recognize #sendTo. It's still a mystery to me why that is. ---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 |
In reply to this post by Mark Miller
> On 28.12.2019, at 05:09, Mark Miller <[hidden email]> wrote: > > 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). The difference is the missing colon in the message. Try (Message selector: #sendTo: argument: '5') sendTo: (Message selector: #asInteger) instead of (Message selector: #sendTo argument: '5') sendTo: (Message selector: #asInteger) Best regards -Tobias > > 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] _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |