[squeak-dev] Re: What is equivalence? (was: The Trunk: Collections-eem.603.mcz)

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Thu Feb 5 09:34:36 UTC 2015


As a side note, sometimes I'd like to relax =.
For example (1 to: 3) = #( 1 2 3) is a problem
- it either violate the hash equality or prevent an efficient hash
computation for Intervals
- it violates transitivity of = - indeed (3 to: 2) and (5 to: 4) are not
equal because they are (historically) used for marking different cursor
positions in a Text, but they both equal #()

They behave similarly enough to be easily exchanged, so we might express
this with hasSameElements or isSameSequence but not necessarily =, = is too
strong IMO.

2015-02-05 3:38 GMT+01:00 Chris Muller <ma.chris.m at gmail.com>:

> > IMO that's a bug.   And the bug is that WeakArray species = WeakArray,
> > whereas it should be Array.  If one selects/rejects/copies a WeakArray
> the
> > result is more useful if it is strong.  It would be interesting to make
> the
> > change and see what effect it has on the standard test suite.
>
> Indeed..
>
> >> I think the answer is because #= (not any other method, just #=) needs
> >> to care about which _implementation_ of the argument which is passed
> >> when considering true equivalence to another object.
> >
> > IMO the problem is because coming up with general purpose #=
> implementations
> > is hard.  You must have seen the controversy my definition of
> > CompiledMethod>>#= has caused over recent years.  #= has evolved a lot
> since
> > Smalltalk-80 as its been more affordable to be cleverer, but that
> evolution
> > also shows that its not absolutely obvious what #= should do; it depends
> on
> > context, and current definitions of #= are general agreements of useful
> > behaviour, some of these agreements having been made a long time ago.
>
> Being cleverer in #= feels right but general agreements also feels
> right in terms of having dependable contracts.  For example, its
> really nice that everyone has "agreed" to include a valid #hash method
> when they write an #= method.   We just do it regardless whether we
> actually think we will put them in a HashedCollection.
>
> >> I agree we human developers can consider unequal but same-quacking
> >> objects interchangeable in our fuzzy minds when we design our
> >> applications, and that is powerful, however, *within the system*, I
> >> just it needs #= to make implementation-specific distinctions,
> >> especially for as base-classes as Array and Dictionary.
> >
> > One thing #= should do is accept any object as an argument without error.
>
> Another very good general agreement for equivalence testing.  I agree!  :)
>
> > This wasn't always the case, but Smalltalk was not and never will be
> > perfect.  Apart from that, what #= means is something we have to
> negotiate.
> > I don't think my recent changes broke anything.
>
> I don't think anything will be broken.  None of my outboard
> SpecialDictionary's implement isDictionary.  It gave me pause to
> wonder what it should answer..
>
> >> This seems to be reflected by most of the #= implementations in the
> >> system, which check either #class, #species, or #isKindOf:.
> >
> > Few of them use isKindOf:.  Some use class or species.  Some use
> #isFoo.  I
> > don't see that #isFoo is worse than #class or #species.  Do you think it
> is?
>
> Hm.  In any other method besides #=, #isFoo is always better.  In
> Dictionary>>#=, it will perform better, it probably won't break
> anything even external.  So, definitely not worse.  :)  Just making
> sure when changing such a method as Dictionary>>#=...
>
>  - Chris
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20150205/e215442e/attachment.htm


More information about the Squeak-dev mailing list