Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
RE: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
- X-seq: zsh-workers 5834
- From: "Andrej Borsenkow" <borsenkow.msk@xxxxxx>
- To: "Sven Wischnowsky" <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>, <zsh-workers@xxxxxxxxxxxxxx>
- Subject: RE: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
- Date: Tue, 16 Mar 1999 21:07:13 +0300
- Importance: Normal
- In-reply-to: <199903150946.KAA09918@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
> - makes the treatment of `${${...}...}' (hopefully) consistent (and
> this is a answer to one of Peter's questions above). The rule is:
> the inner `${...}' is broken into array elements if it yields more
> than one word and the whole thing is not quoted or if it is quoted and
> the `@' flag is used. I'd like to hear comments if you think that
> this looks and feels like the right thing.
What do you mean "one word"? Array with single element yields one word. And
it is very important with subscription (that behaves very funny anyway - see
later). I prefer the case, when array yields array irrespectively of number
of the elements.
This is suggestion I had long ago. May be, it is the same, as you mean, but
explicitly stated:
without qoutes
- ${array} always gives array
- ${scalar} always gives scalar
- ${array[sub]} gives scalar
- ${array[sub1,sub2]} gives array (slice)
- ${(split)something} always gives array (may be, with single element)
- ${(join)something} always gives scalar
- $~ is considred "spliting" in this respect
in quotes
- without (@) all yields scalar
- with (@) the result is array _for_the_next_level_ (for those operations,
that yield array). The point is, the flags and subscription are applied, as
if it were array - and the result is converted to scalar unless (@) is given
as well.
That is, "${${(@)array}[1,3]} gives 1,2,3 elements of array as scalar. And
"${(@)${(@)array}[1,3]}" - the same, but as three words.
Quoting does not change the fact, that innermost parameter is array or
scalar. So, in e.g. "${${(@f)array}[1,3]}", the array elements are splitted
using new lines, then three first resulting elemnts are taken and result is
scalar (single word). In "${(f)scalar}" the scalar is first splitted thus
giving array, and this array is then converted to scalar. Without quoting,
${(f)scalar} gives array. The point is, the "type" of element is propagated
to the top level. And some flags change this type.
About subscription: in ${foo[bar]} - what is "parameter expansion"? Do we
"expand" ${foo} first (using whatever flags are given) and then apply
subscription to the result - or is the whole considered as expansion? In
this case, any (...) flag should be applied _after_ subscription was taken.
This is crucial with (@) flag. I'd prefer the case, when in
"${(@)array[sub1,sub2]}" (@) aplied to the slice. That is consistent and
gives you the way to control type of the whole expression. And the type of
array is determined using rules above.
And now the really funny results (for me at least)
bor@itsrm2:~%> foo=bar
bor@itsrm2:~%> print ${${foo[1]}}
b
this is O.K.
bor@itsrm2:~%> print ${${foo}[1]}
bar
Sorry? Why ${foo} suddenly becomes array?
bor@itsrm2:~%> print "${${foo}[1]}"
b
With some imagination ...
bor@itsrm2:~%> print "${${(@)foo}[1]}"
b
??? Und I always believed, ${(@)foo} is array ...
bor@itsrm2:~%> print "${(@)${foo}[1]}"
bar
Poor, poor ZSH users ...
cheers
/andrej
Messages sorted by:
Reverse Date,
Date,
Thread,
Author