[Newbies] Re: Questions about primitives - how to avoid one ?
Klaus D. Witzel
klaus.witzel at cobss.com
Mon Feb 18 09:02:50 UTC 2008
Hi C'edrick,
on Mon, 18 Feb 2008 01:10:41 +0100, you wrote:
> David T. Lewis wrote:
>> If you comment out the primitive like this is should definitely work:
>>
>
> If I comment out the primitive, in Float>>= ... and put a self halt
> after, the halt point has no effect.
This is correct, both your observation and the corresponding behavior of
Squeak's VM. There are some message selectors whose method is only looked
up if receiver/args don't match, for performance reason. To this belongs
#= (bytecode #182) which is first tried for SmallInteger receiver/args,
then if that fails tried for Float receiver/args, and if that also fails
then routine #bytecodePrimEqual in Squeak's VM performs a normal send
(which would then find the primitive number and/or the Smalltalk code if
the primitive where absent or failed).
Looks complicated but works *fast* (only less failure is more speed :)
For what you want to do I'd suggest you duplicate method Float>>#= as
Float>>#~=~ (just add the two ~ in Float's #= selector and alt-s) and then
you can do
1.234 ~=~ 1.234
and the changes you do to your #~=~ method then do what you want (it's
Smalltalk land :)
HTH.
/Klaus
More information about the Beginners
mailing list