Fwd: hasEqualElements:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
26 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Fwd: hasEqualElements:

Stéphane Ducasse



Hi

(SortedCollection new addAll: #(9 2 3 ); yourself)
hasEqualElements: (OrderedCollection withAll: #(9 2 3)) -> false

hasEqualElements: 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.
This should probably replace the current definition of #= ."

| size |
(otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
(size := self size) = otherCollection size ifFalse: [^ false].
1 to: size do:
[:index |
(self at: index) = (otherCollection at: index) ifFalse: [^ false]].
^ true

For me the name of this method is misleading and I would really like to renaming it
hasStructurallyEqualElements: and have new one doing hasEqualElements:

What do you think?
I would like a beautiful world....

Stef (freezing with a flu in my bed.... cool christmax).




_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Nicolas Cellier
2009/12/23 Stéphane Ducasse <[hidden email]>:

>
>
>
> Hi
>
> (SortedCollection new addAll: #(9 2 3 ); yourself)
> hasEqualElements: (OrderedCollection withAll: #(9 2 3)) -> false
>
> hasEqualElements: 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.
> This should probably replace the current definition of #= ."
>
> | size |
> (otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
> (size := self size) = otherCollection size ifFalse: [^ false].
> 1 to: size do:
> [:index |
> (self at: index) = (otherCollection at: index) ifFalse: [^ false]].
> ^ true
>
> For me the name of this method is misleading and I would really like to
> renaming it
> hasStructurallyEqualElements: and have new one doing hasEqualElements:
>
> What do you think?
> I would like a beautiful world....
>
> Stef (freezing with a flu in my bed.... cool christmax).
>
>

Didn't VW had a #isSameSquenceAs:

Nicolas

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

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Stéphane Ducasse
No but I will look because I do not remember where I saw the difference and
we need it.

Stef
On Dec 23, 2009, at 10:08 AM, Nicolas Cellier wrote:

> isSameSquenceAs


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Eliot Miranda-2
In reply to this post by Nicolas Cellier


On Wed, Dec 23, 2009 at 1:08 AM, Nicolas Cellier <[hidden email]> wrote:
2009/12/23 Stéphane Ducasse <[hidden email]>:
>
>
>
> Hi
>
> (SortedCollection new addAll: #(9 2 3 ); yourself)
> hasEqualElements: (OrderedCollection withAll: #(9 2 3)) -> false
>
> hasEqualElements: 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.
> This should probably replace the current definition of #= ."
>
> | size |
> (otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
> (size := self size) = otherCollection size ifFalse: [^ false].
> 1 to: size do:
> [:index |
> (self at: index) = (otherCollection at: index) ifFalse: [^ false]].
> ^ true
>
> For me the name of this method is misleading and I would really like to
> renaming it
> hasStructurallyEqualElements: and have new one doing hasEqualElements:
>
> What do you think?
> I would like a beautiful world....
>
> Stef (freezing with a flu in my bed.... cool christmax).
>
>

Didn't VW had a #isSameSquenceAs:

Yes.
 

Nicolas

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

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Eliot Miranda-2
In reply to this post by Nicolas Cellier


On Wed, Dec 23, 2009 at 1:08 AM, Nicolas Cellier <[hidden email]> wrote:
2009/12/23 Stéphane Ducasse <[hidden email]>:
>
>
>
> Hi
>
> (SortedCollection new addAll: #(9 2 3 ); yourself)
> hasEqualElements: (OrderedCollection withAll: #(9 2 3)) -> false
>
> hasEqualElements: 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.
> This should probably replace the current definition of #= ."
>
> | size |
> (otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
> (size := self size) = otherCollection size ifFalse: [^ false].
> 1 to: size do:
> [:index |
> (self at: index) = (otherCollection at: index) ifFalse: [^ false]].
> ^ true
>
> For me the name of this method is misleading and I would really like to
> renaming it
> hasStructurallyEqualElements: and have new one doing hasEqualElements:
>
> What do you think?
> I would like a beautiful world....
>
> Stef (freezing with a flu in my bed.... cool christmax).
>
>

Didn't VW had a #isSameSquenceAs:

Nicolas

 
<methods>
<class-id>Core.SequenceableCollection</class-id> <category>comparing</category>

<body package="Collections-Abstract" selector="isSameSequenceAs:">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</body>
</methods>


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.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Stéphane Ducasse
Excellent the Browser did not find it.
So now I understand where I got used to the idea of having the difference between
sameElements and sameStructuralElements.
Tx eliot I will read again in VW.

Stef

On Dec 23, 2009, at 7:10 PM, Eliot Miranda wrote:

>
>
> On Wed, Dec 23, 2009 at 1:08 AM, Nicolas Cellier <[hidden email]> wrote:
> 2009/12/23 Stéphane Ducasse <[hidden email]>:
> >
> >
> >
> > Hi
> >
> > (SortedCollection new addAll: #(9 2 3 ); yourself)
> > hasEqualElements: (OrderedCollection withAll: #(9 2 3)) -> false
> >
> > hasEqualElements: 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.
> > This should probably replace the current definition of #= ."
> >
> > | size |
> > (otherCollection isKindOf: SequenceableCollection) ifFalse: [^ false].
> > (size := self size) = otherCollection size ifFalse: [^ false].
> > 1 to: size do:
> > [:index |
> > (self at: index) = (otherCollection at: index) ifFalse: [^ false]].
> > ^ true
> >
> > For me the name of this method is misleading and I would really like to
> > renaming it
> > hasStructurallyEqualElements: and have new one doing hasEqualElements:
> >
> > What do you think?
> > I would like a beautiful world....
> >
> > Stef (freezing with a flu in my bed.... cool christmax).
> >
> >
>
> Didn't VW had a #isSameSquenceAs:
>
> Nicolas
>
>  
> <methods>
> <class-id>Core.SequenceableCollection</class-id> <category>comparing</category>
>
> <body package="Collections-Abstract" selector="isSameSequenceAs:">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</body>
> </methods>
>
>
> 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.
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

csrabak
In reply to this post by Eliot Miranda-2
Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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

--
Cesar Rabak

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Eliot Miranda-2


On Wed, Dec 23, 2009 at 10:41 AM, <[hidden email]> wrote:
Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Stéphane Ducasse
Ideally what I would like is

=
        isSameSequenceAs: + same receiver kind (may be overkill)

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."

hasSameElements:
        "Answer whether the receiver's size is the same as otherCollection's size, and each
         of the receiver's elements is included in otherCollection and vice versa."

Stef




On Dec 23, 2009, at 7:58 PM, Eliot Miranda wrote:

>
>
> On Wed, Dec 23, 2009 at 10:41 AM, <[hidden email]> wrote:
> Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Nicolas Cellier
2009/12/23 Stéphane Ducasse <[hidden email]>:

> Ideally what I would like is
>
> =
>        isSameSequenceAs: + same receiver kind                  (may be overkill)
>
> 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."
>
> hasSameElements:
>        "Answer whether the receiver's size is the same as otherCollection's size, and each
>         of the receiver's elements is included in otherCollection and vice versa."
>
> Stef
>

like #(2 2 3) hasSameElements: #(2 3 3) -> true
but #(2 2 3) asSet hasSameElements: #(2 3 3) -> false

?

>
>
>
> On Dec 23, 2009, at 7:58 PM, Eliot Miranda wrote:
>
>>
>>
>> On Wed, Dec 23, 2009 at 10:41 AM, <[hidden email]> wrote:
>> Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Stéphane Ducasse

> 2009/12/23 Stéphane Ducasse <[hidden email]>:
>> Ideally what I would like is
>>
>> =
>>        isSameSequenceAs: + same receiver kind                  (may be overkill)
>>
>> 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."
>>
>> hasSameElements:
>>        "Answer whether the receiver's size is the same as otherCollection's size, and each
>>         of the receiver's elements is included in otherCollection and vice versa."
>>
>> Stef
>>
>
> like #(2 2 3) hasSameElements: #(2 3 3) -> true
> but #(2 2 3) asSet hasSameElements: #(2 3 3) -> false

no
as
>> hasSameElements:
>>        "Answer wether each of the receiver's elements is included in otherCollection and vice versa."


Sorry another victim of copy and paste.

Stef

>
> ?
>
>>
>>
>>
>> On Dec 23, 2009, at 7:58 PM, Eliot Miranda wrote:
>>
>>>
>>>
>>> On Wed, Dec 23, 2009 at 10:41 AM, <[hidden email]> wrote:
>>> Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

csrabak
In reply to this post by Nicolas Cellier
Em 23/12/2009 19:17, Nicolas Cellier < [hidden email] > escreveu:

> 2009/12/23 Stéphane Ducasse :
> > Ideally what I would like is
> >
> > = isSameSequenceAs: + same receiver kind (may be overkill)
> >
> > 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."
> >
> > hasSameElements:
> >        "Answer  whether  the  receiver's   size  is  the  same  as
> >         otherCollection's  size,   and  each  of   the  receiver's
> >         elements is included in otherCollection and vice versa."
> > Stef
> >
>  like #(2 2 3) hasSameElements: #(2 3 3) -> true

>  but #(2 2 3) asSet hasSameElements: #(2 3 3) -> false

Can someone illustrate this less enlightened coder what common programming pattern this wonderful method would of use for?

--
Cesar Rabak


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Igor Stasenko
In reply to this post by Eliot Miranda-2
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 <[hidden email]>:

>
>
> On Wed, Dec 23, 2009 at 10:41 AM, <[hidden email]> wrote:
>>
>> Em 23/12/2009 16:10, Eliot Miranda < [hidden email] > 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
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

csrabak
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 <[hidden email]> 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 < [hidden email] > 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
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Nicolas Cellier
2009/12/24  <[hidden email]>:

> 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 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 <[hidden email]> 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 < [hidden email] > 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
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

csrabak
Em 23/12/2009 22:51, Nicolas Cellier <[hidden email]> 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"

1.0 at: 1.0 size -> 0 "this will not work anymore in Pharo because
indices have to be Integer in Pharo right now"

HTH

--
Cesar Rabak


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Nicolas Cellier
2009/12/24  <[hidden email]>:

> Em 23/12/2009 22:51, Nicolas Cellier <[hidden email]> 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"
>
> 1.0 at: 1.0 size -> 0 "this will not work anymore in Pharo because
> indices have to be Integer in Pharo right now"
>

I mean in VW, size would be > 0 but #at: would raise a debugger.

Nicolas

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

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Levente Uzonyi-2
In reply to this post by csrabak
On Thu, 24 Dec 2009, [hidden email] wrote:

> Em 23/12/2009 22:51, Nicolas Cellier <[hidden email]> 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

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

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

csrabak
Em 24/12/2009 01:21, Levente Uzonyi < [hidden email] > escreveu:

>  On Thu, 24 Dec 2009, [hidden email] 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.

--
Cesar Rabak

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: hasEqualElements:

Levente Uzonyi-2
On Thu, 24 Dec 2009, [hidden email] wrote:

> Em 24/12/2009 01:21, Levente Uzonyi < [hidden email] > escreveu:
>
>>  On Thu, 24 Dec 2009, [hidden email] 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. :)


Levente

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

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
12