Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: What makes an array sorted and a hash unsorted?

by ikegami (Patriarch)
on Jun 01, 2009 at 17:54 UTC ( [id://767340]=note: print w/replies, xml ) Need Help??


in reply to Re^3: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?

Yes, they'd be considered sorted.

Even with that change, I think we'll still get EXACTLY the same questions we get today. People want custom ordering of keys when dealing with hashes (as opposed to custom ordering of values when dealing with arrays).

So if your claim is true, that means the answer we currently give ("hashes are unsorted") is wrong because the hashes being sorted wouldn't help at all.

I actually believe that hash are unsorted, and I believe the answer we are giving is right.

When people think they have a hash in a particular order, it isn't generally ASCIIbetical order, but the order they put the elements into it.

Exactly. It's how we use hashes that makes them unsorted. The keys are actually part of the value, and thus can't be used for ordering.

  • Comment on Re^4: What makes an array sorted and a hash unsorted?

Replies are listed 'Best First'.
Re^5: What makes an array sorted and a hash unsorted?
by Roy Johnson (Monsignor) on Jun 01, 2009 at 18:07 UTC
    "Hashes are not sorted the way you think they are sorted" would be correct today as well as with your change. However, it is also (theoretically) possible to implement hashes that retain an order unrelated to their keys. If that were implemented, it would "help", and so the problem is that hashes are unsorted -- in that way.

    I still contend that it is the language that makes them unsorted. It is not merely how we use them. Order has to be imposed externally on the data. There is no intrinsic ordering.


    Caution: Contents may have been coded under pressure.

      So hashes aren't ordered because the following doesn't work?

      $h{foo} = 'a'; $h{bar} = 'b'; $h{baz} = 'c'; is(join(' ', values(%h)), "a b c");

      I guess arrays aren't ordered either, then.

      $a[2] = 'a'; $a[0] = 'b'; $a[1] = 'c'; is("@a", "a b c");

      Order has to be imposed externally on the data in the case of arrays too. It's just there's a convenient way of doing that when the keyspace isn't sparse (namely, the range operator).

        You're trying too hard. You're now saying that there must be exactly one kind of ordering that constitutes ordering, and nothing else can be considered ordered. Or that every ordering must be implemented for a thing to be considered ordered. I'm not sure which you're contending; they're both pretty stupid notions, which is why it surprises me to see you pushing it as a serious argument.

        Order has to be imposed externally on the data in the case of arrays too.
        No, order is intrinsic to arrays. Not every possible order, but the one that is intrinsic. Any other ordering would have to be imposed. Arrays have one intrinsic ordering. Hashes have zero intrinsic orderings.


        Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://767340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-18 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found