[ANSI-Smalltalk] Protocol extensions - Object
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Sep 8 07:32:21 BST 2008
On 8 Sep 2008, at 6:04 pm, Paolo Bonzini wrote:
> Squeak overloads #perform: for a Message argument, see
>
> http://lists.squeakfoundation.org/pipermail/squeak-dev/2007-September/120697.html
>
> for an example. What do you think about it?
I think I can't find it in Squeak 3.10.
Here's the source code for Object>>perform:
perform: aSymbol
"Send the unary selector, aSymbol, to the receiver.
Fail if the number of arguments expected by the selector is not zero.
Primitive. Optional. See Object documentation whatIsAPrimitive."
<primitive: 83>
^ self perform: aSymbol withArguments: (Array new: 0)
I don't know where to find the implementation of a primitive,
so a test was the way forward. If #perform: worked with Messages,
then
1 perform: (Message selector: #+ argument: 2)
should be the same as 1 + 2, no? In fact it produces a
MessageNotUnderstood exception.
What Squeak _does_ have is Message sentTo: anObject,
so
(Message selector: #+ argument: 2) sentTo: 1
works. That's not in VW, at least, not in VWNC 5, but
Message>>
sentTo: anObject
^anObject perform: selector withArguments: args
does the trick, and more efficient implementations are of course
possible.
Overloading #perform: raises the question
"what should #perform:withArguments: do when the 'selector'
is a Message with arguments of its own?"
Adding Message>>sentTo: does not raise that question.
It does seem odd to have Messages with no direct way to send
them, so adding #sentTo: would seem to make sense.
More information about the ANSI-Smalltalk
mailing list