Collection squared but what about fractions.
John M McIntosh
johnmci at smalltalkconsulting.com
Tue Jun 5 00:47:01 UTC 2001
> >>>>> "Andreas" == Andreas Raab <Andreas.Raab at gmx.de> writes:
>
>Andreas> John,
>Andreas> How about making a little tweak in Fraction along the lines of:
>
>Fraction> * aNumber
>Andreas> self == aNumber ifTrue:[
>Andreas> "special case for squaring fractions"
>Andreas> ^self squared]
>Andreas> "...."
>
>Andreas> This might even help in some other cases (note that the
>above uses #== to
>Andreas> prevent doing a full comparison in case of a non-fractional
>argument).
>
>Does that actually make sense? Are all 1/2's identical? I can see
>using "=", but not "==".
>
>Just tested:
>
>(1/2) == (1/2) false
>(1/2) = (1/2) true
>
>So, nope, that true branch would most likely never get triggered.
Ah, you need to step back and look at the squared in Collection, that uses
each * each so each == each. Evaluating (1/2) == (1/2) is false
because of the way the compiler builds/treats the (1/2). In VisualAge
it would be true because it's compiler (in 3.x) would treat the two
constants (1/2) as the same object.
--
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com
===========================================================================
More information about the Squeak-dev
mailing list
|