Yukihiro Matsumoto wrote:
> Hi,
> 
> In message "Re: OK... :) question about hash and array literals"
>     on Sun, 5 Sep 2004 01:38:42 +0900, Hal Fulton <hal9000 / hypermetrics.com> writes:
> 
> |However, if order in literals is irrelevant, then hashes are not truly
> |ordered entities, are they?
> 
> My opinion is preserving order reduces some "pitfalls".  Reducing
> pitfalls is a good thing.  To be honest, I don't care whether Hash
> being "true" ordered entity or not.

I defer to your judgment of course.

But a large part of my desire for an ordered collection of this nature
is the desire to write ordered literals.

Arrays and hashes in Ruby would not be nearly so convenient and clear
if one had to write:

   arr = Array.new(3,5,7,9,11)
   hsh = Hash[1,2,3,6,9,12)

If a Hash object preserved order, but a literal did not guarantee an order --
then to preserve the order with literals, we would have to do something like:

   hash = {1=>2}.update(3=>4).update(5=>6)

instead of just

   hash = {1=>2, 3=>4, 5=>6}

Is it a possible option to change the semantics of [x=>y] ?

   h1 = {1=>2, 3=>4}   # order not guaranteed
   h2 = [1=>2, 3=>4]   # order guaranteed

I realize (now) that [x=>y] is currently an array with a
single element which is a hash.


Hal