Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: 3.1.5 - sample associative array implementation



"Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Nov 12,  7:04pm, Timothy Writer wrote:
> > Subject: Re: PATCH: 3.1.5 - sample associative array implementation
> [Referring to ksh93]
> > 
> >     typeset -A foo
> >     foo[bar]=baz
> >     echo ${!foo}
> > 
> > just prints "foo".  Makes sense because foo is not a nameref.
> 
> That's not what I would have expected; I would have expected it to either
> (a) behave the same as ${foo} [which means what, when foo is an associative
> array?] or (b) print nothing, because there's no variable to which the value
> of foo can possibly refer.  Printing its own *name* like that isn't sensible
> to me.

In ksh93, $arrayname is a synonym for ${arrayname[0]}.  This appears to be
true for indexed arrays _and_ associative arrays.

If you think of nameref as being like a symbolic link and ${!foo} as being
like lstat(), it makes perfect sense (at least to my twisted mind) that
${!foo} is just "foo" for ordinary (non nameref) variables.

-- 
Tim Writer                                              Tim.Writer@xxxxxxxxxx
FTL Solutions Inc.
Toronto, Ontario, CANADA



Messages sorted by: Reverse Date, Date, Thread, Author