David Alan Black <dblack / candle.superlink.net> writes:

> In spite of being an advocate of having two different names, I do
> agree that conceptually an array is essentially a hash on positive
> integers.  (See for example [ruby-talk:6611] and [ruby-talk:6663].)
> In fact, looking at arrays and hashes that way makes me wonder about
> what *exactly* is common to them, and what implications that has.  I
> keep thinking of a phantom module called "Hashable", and wishing it
> existed....  

I'm not sure I agree that they are essentially the same. For example:

  a = []
  a[0] = 0
  a[10] = 10
  p a     #=> [0, nil, nil, nil, nil, nil, nil, nil, nil, nil, 10]

  b = {}
  b[0] = 0
  b[10] = 10
  p b     #=> {0=>0, 10=>10}

An array is a vector, while a hash is an indexed collection.  Arrays
have key-ordering, while hashes are unordered.

However, I _would_ agree that both arrays and hashes might be
derivable from some underlying collection class.


Regards


Dave