Question: CompiledMethod evaluation
Stefan Matthias Aust
sma at 3plus4.de
Sat Jun 10 09:58:14 UTC 2000
At 10:48 09.06.00 +1200, Brent Pinkney wrote:
>CompiledMethod>>#valueWithReceiver: aReceiver arguments: anArray
>
> | result |
>
> aReceiver class addSelector: #Bollocks withMethod: self.
>
> result _ self numArgs isZero
> ifTrue: [ aReceiver perform: #Bollocks ]
> ifFalse: [ aReceiver perform: #Bollocks withArguments:
>anArray ].
>
> aReceiver class removeSelector: #Bollocks.
>
> ^result
I'd recommend to use #ensure: to undo the method dictionary modification
also on errors. Then, the #isZero test isn't really needed. Furthermore,
#removeSelector: logs the deletation which is probably not
wanted. Finally, you want to make sure that the symbol used is definitely
not existing. And of course, it should work for more than one call. So
there's my suggestion:
valueWithReceiver: aReceiver arguments: anArray
| selector |
selector _ Symbol new.
aReceiver class addSelector: selector withMethod: self.
^ [aReceiver perform: selector withArguments: anArray]
ensure: [aReceiver class removeSelectorSimply: selector]
Luciano's code might be even better, but it's also much more obscure ;-)
--
Stefan Matthias Aust // Bevor wir fallen, fallen wir lieber auf
More information about the Squeak-dev
mailing list
|