i will take a look at this

Logan Capaldo wrote:
> In PHP $ary[1] = 'hans' must be an array. I can't create something else
> that supports the same syntax.
>
> In Ruby, ary[1] = 'hans' could be an array, could be a hash, could be a
> string, could be any user created class. It could also mask errors,
in ruby, ary[1] = 'hans' does not do a thing, it only complains that
nil has no []= method defined.
in php, where someone has defined that using []= on a undefined
variable would result in the creation of an (sparse) array, he could
have defined that it would result in creation of a string, but he
didnt.

> Like for instance:
> b = 7
> b[3] = 2
> Should 'b' now magically be turned into [nil, nil, nil, 2] ? (I don't
> know, I don't think so, but maybe it should).

no, that would mean that i overloaded the []= method in Fixnum, but im
only talking about NilClass...
the [] at Fixnum shows you the value of the bit at this position, maybe
it makes sense to have a []= as a bit setter/unsetter, but its not in
there, i dont mind, i dont care, i dont want to define it.

> When asking for magic, you must always consider the impact it will have
> on the rest of the language and the rest of the programs out there.

like said before im not overloading it for anything but nil, and
everybody that uses []= on nil now gets errors, and most likely
"repairs" his code.

> Ahh, but [] is different from []. ;) Rather, when I say a = [] it has
> nothing to do with a[i] but rather it's writing an array literal (like
> PHP's array()).
> [1,2,3] would be the same as array(1,2,3) in PHP
> [1,2] would be the same as array(1,2) in PHP
> [1] would be the same as array(1) in PHP
> and [] is the same as array() in PHP.
> It's just an (un?)happy coincidence that it looks the same as the index
> operator.

i know its different, and in my opinion its a happy "coincidence", if
it was coincidence at all, using "" for example would not be so
inuitive for "shortcut array creation".

> > my problem is that if i have an multi dimensional array, and it needs
> > to grow (by itself if i assign values outside of the allocated space),
> > the newly created will be "nil" so i cant use my own class for that.
> >
> It doesn't have to be, that's why you write your own class.

i already see the light, in php i dont think that something like this
OrderedAutoHash would be possible to implement by the "user" because
the [] is a language construct there and a method call here.