From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28315 invoked from network); 17 Mar 1999 09:20:39 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 17 Mar 1999 09:20:39 -0000 Received: (qmail 7 invoked by alias); 17 Mar 1999 09:14:10 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 5834 Received: (qmail 29983 invoked from network); 17 Mar 1999 09:14:09 -0000 From: "Andrej Borsenkow" To: "Sven Wischnowsky" , Subject: RE: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter Date: Tue, 16 Mar 1999 21:07:13 +0300 Message-ID: <003c01be6fd7$d155b760$21c9ca95@mowp.siemens.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal In-Reply-To: <199903150946.KAA09918@beta.informatik.hu-berlin.de> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 > - 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