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.

In Squeak where the method is implemented slightly different, an 
UndefinedObject>>size does return the zero for nil Objects but will raise an 
error for non indexable objects.

So except if we are willing to have a very specific dialect of Smalltalk in 
Pharo, we'll probably have to fix the protocol for Object>>size, and then the 
line above will for most of the cases automatically return false as soon 
otherCollection happen to be isKindOf: Collection not.

OTOH, if we keep Pharo as is, the above line will also by the automatism 
already described give the MNU as an error. . .

--
Cesar Rabak

Em 23/12/2009 20:22, Igor Stasenko <[email protected]> escreveu:


Eliot is right: the argument of isSameSequenceAs: should be already of
SequenceableCollection kind ,
otherwise there is no sense asking , whether some collection has same
sequence as another one, which probably not sequencable.

By analogy, asking  'isSameColor: anObject' , we already stating, that
an argument - anObject having a #color property.
Otherwise, if its not, this should lead to error, but not returning 'false'.


2009/12/23 Eliot Miranda :
>
>
> On Wed, Dec 23, 2009 at 10:41 AM,  wrote:
>>
>> Em 23/12/2009 16:10, Eliot Miranda < [email protected] > escreveu:
>>
>> >
>> >  Core.SequenceableCollection comparing
>> >  isSameSequenceAs: otherCollection
>> >
>> >   "Answer whether the receiver's size is the same as otherCollection's
>> >   size, and each of the receiver's elements equal the corresponding
>> >   element of otherCollection."
>> >
>> >  | size |
>> >  (size := self size) = otherCollection size ifFalse: [^false].
>> >  1 to: size do: [:index |
>> >  (self at: index) = (otherCollection at: index) ifFalse: [^false]].
>> >  ^true
>> >
>> >  i.e.   trust  the   caller   is  providing   a   sequence  and   if
>> > otherCollection  doesn't  implement at:  there  will  be a  run-time
>> > error, hence any otherCollection isKindOf: SequenceableCollection is
>> > just wasted cycles.
>> >
>>
>> I don't think that "trusting the caller" makes sense in this case, so
>> I propose instead that you implementation be complemented by:
>>
>> Object>>isSameSequenceAs: otherCollection
>> ^false
>
> We're talking about the argument otherCollection not the receiver.  i.e.
> leaving out isKindOf: in
> isSameSequenceAs: otherCollection
>          "Answer whether the receiver's size is the same as
> otherCollection's size, and each
>           of the receiver's elements equal the corresponding element of
> otherCollection."
>
>          | size |
>          (otherCollection isKindOf: SequenceableCollection) ifFalse:
> [^false]. "this is a horrible wart"
>          (size := self size) = otherCollection size ifFalse: [^false].
>          1 to: size do: [:index |
>                  (self at: index) = (otherCollection at: index) ifFalse:
> [^false]].
>          ^true
> You could use double dispatching:
> SequenceableCollection>>isSameSequenceAs: otherThing
>     ^otherThing isSameSequenceAsSequence: self
> SequenceableCollection>> isSameSequenceAsSequence: aSequenceableCollection
>     aSequenceableCollection size ~= self size ifTrue: [^false].
>     etc
> Object isSameSequenceAsSequence: aSequenceableCollection
>     ^false
> but I think in this case it's overkill.
>>
>> --
>> 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
>



-- 
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
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