extending array macro language: array[] = expr

Bert Wesarg bert.wesarg at googlemail.com
Thu Apr 10 14:53:57 CEST 2008


On Thu, Apr 10, 2008 at 10:07 AM, Joachim Lous <joachim at lous.org> wrote:
> On Thu, Apr 10, 2008 at 6:23 AM, Tony Balinski <ajbj at free.fr> wrote:
>  >  A bit misleading this: if you have the array
>  >   arr[0] = 0
>  >   arr[1] = 1
>  >   arr["key0"] = 2
>  >   arr["key1"] = 3
>  >  adding arr[] = 999 will provide arr[2], not arr[4] as I would expect from the
>  >  right-hand-side behaviour of arr[] (it's not the same as arr[arr[]] = 999). I
>  >  find this counter-intuitive.
>
>  Maybe so, but the only other common languages I know that mix numeric
>  and associative arrays in the same object are Javascript and PHP, and
>  both assign numeric keys in this way when you push an unnamed value
>  into an array (although with Javascript you have to call "push", not
>  just usean empty bracket)
>
I didn't know about JS, but I have modeled this after the PHP behaviour.

But I can understand the point from Tony and Aaron.

Maybe a drastically syntax extension is needed:

rvalue: arr[@]        := return max numeric index + 1
lvalue: arr[@] = expr := push expr at position max numeric index + 1

Bert


More information about the Develop mailing list