On Thu, Dec 24, 2009 at 12:21 PM, Levente Uzonyi <[email protected]> wrote:

> On Thu, 24 Dec 2009, [email protected] wrote:
>
> > Em 24/12/2009 01:21, Levente Uzonyi < [email protected] > escreveu:
> >
> >>  On Thu, 24 Dec 2009, [email protected] wrote:
> >>
> >>> Em 23/12/2009 22:51, Nicolas Cellier escreveu:
> >>>
> >>>>  2009/12/24 :
> >>>>> Igor, Sometimes  a fallacy can  be written by clever  people, by
> >>>>> accident.  If you pay attention to the line: (size := self size)
> >>>>> =  otherCollection  size ifFalse:  [^false].   I all  Smalltalks
> >>>>> [Except  Pharo  to  what  I   wrote  a  comment  in  issue  1637
> >>>>> http://code.google.com/p/pharo/issues/detail?id=1637] this would
> >>>>> return  false  if  self  be  not  Collection  or  otheCollection
> >>>>> isKindOf:  Collection  not.    This  happens  because  in  these
> >>>>> Smalltalks Object>>size returns zero.
> >>>>> Not  so sure.   Try  1.0 size,  then  1.0 at:  1.0  size in  you
> >>>>  favourite
> >>>> dialect.
> >>> Nicolas,
> >>> In Squeak 3.10.2-7179:
> >>> 1.0 size -> 2 "OK I'm surprised here"
> >>  It's  not surprising  since Float  is a  variable word  subclass of
> >> Number. :)
> >>
> >>> 1.0 at: 1.0 size -> 0 "this will not work anymore in Pharo because
> >>> indices have to be Integer in Pharo right now"
> >>  The index is 2, so it will  work. Btw, I wonder how pharo can force
> >> Integer indices if the vm accepts Floats too.
> >>
> > Levente,
> >
> > In fact VM _does_ _not_ accept Floats as indices.  There is a hack in
> > Squeak code (which in fact contradicts the  comment in the method) in
> > the #at: methods that make a conversion from Number to Integer.
> >
> > If you comment that code out you'll see the VM #at: (via the primitive)
> > will fail with Floats.
>
> True, and cool, since this hack can be removed. Now I wonder why did I
> assume that the vm has this hack. :)
>



This 'hack' is as old as Smalltalk-80 V2 and is AFAICT in all Smalltalk-80
derived Smalltalks:

!Object methodsFor: 'accessing'!
at: index
    "Answer the value of an indexable field in the receiver. Fail if the
    argument index is not an Integer or is out of bounds. Essential. See
    documentation in Object metaclass."

    <primitive: 60>
    index isInteger
        ifTrue: [self errorSubscriptBounds: index].
    (index isKindOf: Number)
        ifTrue: [^self at: index truncated]
        ifFalse: [self errorNonIntegerIndex]!

It is also free in the sense that the failure code is only invoked when the
primitive fails and so adds nothing to the cost of successful accesses,
which are the high dynamic frequency operation.  It will also show up under
profiling if one is concerned about efficiency, and so isn't a hidden cost.

It is also in keeping with Smalltalk's mixed mode/arbitrary precision
implicit coercion number system that one *can* use fractions or floats as
indices.

Stripping out coercions like this will make the system more brittle.  So
please do *not* remove this "hack".  I think it's a feature and a useful
one.


>
> Levente
>
> >
> > --
> > Cesar Rabak
> >
> > _______________________________________________
> > Pharo-project mailing list
> > [email protected]
> > http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
> >
>
> _______________________________________________
> Pharo-project mailing list
> [email protected]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to