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

${(A)=xxx} - second go - now real bug.



Reading docs once more I noted this:

A
     Create an array parameter with ${...=...}, ${...:=...} or
     ${...::=...}.  If this flag is repeated (as in AA), create an
     associative array parameter.  Assignment is made before sorting or
     padding.  The NAME part may be a subscripted range for ordinary
     arrays; the WORD part *must* be converted to an array, for example
     by using ${(AA)=...} to activate word splitting, when creating an
     associative array.

Please, note the last sentence. It implies, that in case of array/hash
assignment the word is treated as in array assignment - that is, ${(A)foo=bar
baz} is basically the same as foo=(bar baz). At least, I find this natural and
useful. And I have a feeling, that it was once so. Currently we have:

bor@itsrm2:~%> : ${(AA)foo::=bar baz}
zsh: bad set of key/value pairs for associative array

bor@itsrm2:~%> print -l $foo

bor@itsrm2:~%> print ${(t)foo}
association
bor@itsrm2:~%> unset foo
bor@itsrm2:~%> : ${(A)foo::=bar baz}
bor@itsrm2:~%> print -l $foo
bar baz
bor@itsrm2:~%> print ${(t)foo}
array


I suggest changing it to the described. That is,

${foo=bar} - the same as foo=bar (with blanks quoted, 'course)
${(A)foo=bar}, ${(AA)foo=bar} -
             the same as foo=(bar)

A good question is, if we should do globbing in above cases. I dare to say, that
it may be useful ... following the usual rules. That is, no globbing in
${foo=bar} and normal globbing in ${(A)foo=bar}

Additional suggestion - what about iterpreting the (A) and (AA) flags in
${(A):-bar} ? The main reason is, currently it is always producing scalar; but
there are cases (mostly globbing) where I'd like to have array. Again, splitting
is _not_ the same. This would allow to use

${(A):-*.txt}

to get a list of files instead of current

${(f)"$(print -l *.txt)"}

that always has a problem with new lines in file names. And it is more simple
and arguably faster.

And final question: how should the following (from parameter expansion) be
interpreted:

s:STRING:
     Force field splitting (see the option SH_WORD_SPLIT) at the
     separator STRING.  Splitting only occurs in places where an array
     value is valid.

I mean the last sentence?

regards

/andrej



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