[squeak-dev] #= ==> #hash issues

Eliot Miranda eliot.miranda at gmail.com
Thu Nov 22 15:36:18 UTC 2018


Hi Chris,

> On Nov 20, 2018, at 11:11 AM, Chris Cunningham <cunningham.cb at gmail.com> wrote:
> 
> Sorry for the excessive delay in responding to these threads.
>> On Thu, Nov 15, 2018 at 5:36 PM Eliot Miranda <eliot.miranda at gmail.com> wrote:
>> Hi Bert,
>> 
>>> On Thu, Nov 15, 2018 at 4:38 PM Bert Freudenberg <bert at freudenbergs.de> wrote:
>>> Somehow I missed Eliot's version, but unsurprisingly he had exactly the same idea (use "last" not "stop" for hash). I'd still think bitXor: is preferable to bitOr, that is the standard way in almost all hash methods. But ...
>>> 
>>> BUT: I forgot about the super fallback in #=. That makes this discussion pretty much moot, because since
>>> 
>>> 	#(1 2 3) = (1 to: 3) "true"
>>> 
>>> is true, this must also be true:
>>> 
>>> 	#(1 2 3) hash = (1 to: 3) hash  "must be true"
>>> 
>>> So the only proper fix IMHO is to remove #hash from Interval (or replace it with ^super hash and a proper comment)
>> 
>> 
>> We discussed this a couple of weeks ago.  There is no need for 
>>     #(1 2 3) = (1 to: 3) 
>> to be true. 
>>     #(1 2 3) = #[1 2 3]
>> isn’t true.  And we have hasEqualElements:.  So a more coherent approach is for the hack that makes intervals equal to arrays be discarded, and the hashes kept distinct.
>  
> Actually, the hack is that interval is a subclass of SequenceableCollection with species defined as Array. This makes lots of things very nice - like #collect: and #select: just work.  If we removed #species (which would be necessary to make interval and array not be equal), that would require re-implementing these two methods - and many, many more - from the superclasses.
> 
> Basically, that hack is a fundamental part of how the class is built today.

IMO it is not a hack.  But it has nothing to do with whether an Interval with equal elements to an Array is equal to it.  A ByteArray is also a SequenceableCollection and is not equal to an Array if it has equal elements.  It has a different species to Array, but species exists, as you’ve noted, for the convenience of select: & collect: so that immutable collections can answer a suitable mutable class to be used to construct the result.

> 
> Are we ok with us taking on that much of a change?

No one is suggesting changing the species of Interval.

> -cbc
>>  
>>> 
>>> - Bert -
>>> 
>>> 
>> 
>> 
>> -- 
>> _,,,^..^,,,_
>> best, Eliot
>> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20181122/88c6d761/attachment.html>


More information about the Squeak-dev mailing list