[e-lang] [Caja] Equality of mappings in E
Kevin Reid
kpreid at mac.com
Thu Mar 12 06:27:08 EDT 2009
On Mar 11, 2009, at 22:15, Bill Frantz wrote:
> kpreid at mac.com (Kevin Reid) on Tuesday, March 10, 2009 wrote:
>> On Mar 10, 2009, at 16:28, Mark S. Miller wrote:
>>> On Tue, Mar 10, 2009 at 11:01 AM, David-Sarah Hopwood <david.hopwood at industrial-designers.co.uk
>>> wrote:
>>>> Mark S. Miller wrote:
>>>>> ? ["a" => 1, "b" => 2] == ["b" => 2, "a" => 1]
>>>>> # value: false
>>>> I'm surprised. The ASTs of the left- and right-hand sides are
>>>> certainly different, but this is testing whether the values are
>>>> the same. Why aren't the values the same?
>>>
>>> Because their enumeration order is different.
>>
>> Note that if the maps are restricted to have string keys, then it is
>> not impossible to canonicalize the enumeration order.
>
> It would seem that you could canonicalize the order for any ordered
> type,
> including string. The process might have an execution time cost.
Yes; the problem is that key-type is not an explicit property of
ConstMaps, and it would be rather surprising, if not actively
hazardous, to have the behavior "a ConstMap's keys are sorted if the
keys all have op__cmp methods", especially as "are these objects all
of the same type?" is -- nontrivial -- in E.
If you want a "sorted map literal" or to reestablish sortedness you
can always write:
? ["b" => 2, "a" => 1].sortKeys()
# value: ["a" => 1, "b" => 2]
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list