From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9931 invoked from network); 10 May 1999 10:16:00 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 10 May 1999 10:16:00 -0000 Received: (qmail 4978 invoked by alias); 10 May 1999 10:14:45 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 6246 Received: (qmail 4734 invoked from network); 10 May 1999 10:13:17 -0000 Message-Id: <9905100828.AA33594@ibmth.df.unipi.it> To: zsh-workers@sunsite.auc.dk Subject: PATCH: mult_isarr documentation In-Reply-To: ""Bart Schaefer""'s message of "Sun, 09 May 1999 10:49:40 DFT." <990509104940.ZM21070@candle.brasslantern.com> Date: Mon, 10 May 1999 10:28:16 +0200 From: Peter Stephenson Here's what I have for the documentation for 6046 after Sven's and Bart's suggestions. I'm hoping to get the latest compinstall (and consequent compinit) changes finished before producing pws-18. --- Doc/Zsh/expn.yo.ma Mon Apr 26 09:25:08 1999 +++ Doc/Zsh/expn.yo Mon May 10 10:18:42 1999 @@ -717,18 +717,24 @@ performed from the inside outwards. At each level, the substitution takes account of whether the current value is a scalar or an array, whether the whole substitution is in double quotes, and what flags are supplied to the -current level of substitution; the flags are not propagated up to enclosing -substitutions. The value passed back to an enclosing substitution is -always an array, which however will consist of one word if the value was -not itself an array. All the following steps take place where applicable -at all levels of substitution. +current level of substitution, just as if the nested substitution were the +outermost. The flags are not propagated up to enclosing +substitutions; the nested subsitution will return either a scalar or an +array as determined by the flags, possibly adjusted for quoting. All the +following steps take place where applicable at all levels of substitution. +Note that, unless the tt((P)) flag is present, the flags and any subscripts +apply directly to the value of the nested substitution; for example, the +expansion tt(${${foo}}) behaves exactly the same as tt(${foo}). ) item(tt(2.) em(Parameter Subscripting))( If the value is a raw parameter reference with a subscript, such as tt(${)var(var)tt([3]}), the effect of subscripting is applied directly to -the parameter. If the parameter is an array, any second subscript, -indexing on the character in the word, may appear, -e.g. tt(${)var(var)tt([1][2]}). +the parameter. Subscripts are evaluated left to right; subsequent +subscripts apply to the scalar or array value yielded by the previous +subscript. Thus if tt(var) is an array, tt(${var[1][2]}) is the second +character of the first word, but tt(${var[2,4][2]}) is the entire third +word (the second word of the range of words two through four of the +original array). Any number of subscripts may appear. ) item(tt(3.) em(Parameter Name Replacement))( The effect of any tt((P)) flag, which treats the value so far as a @@ -746,6 +752,10 @@ Any remaining subscript (i.e. of a nested substitution) is evaluated at this point, based on whether the value is an array or a scalar; if it was an array, a second subscript for the character in the word may also appear. +Note that tt(${foo[2,4][2]}) is thus equivalent to tt(${${foo[2,4]}[2]}) +and also to tt("${${(@)foo[2,4]}[2]}") (the nested substitution returns an +array in both cases), but not to tt("${${foo[2,4]}[2]}") (the nested +substitution returns a scalar because of the quotes). ) item(tt(6.) em(Modifiers))( Any modifiers, as specified by a trailing tt(#), tt(%), tt(/) @@ -798,20 +808,17 @@ startitem() item(tt("${(@)${foo}[1]}"))( -This produces the result tt(bar baz). First, the inner substitution +This produces the result tt(b). First, the inner substitution tt("${foo}"), which has no array (tt(@)) flag, produces a single word -result. The outer substitution tt("${(@)...[1]}") acts on this result as -if it were a one word array, because of the array flag, so the result is -just that single word. +result tt("bar baz"). The outer substitution tt("${(@)...[1]}") detects +that this is a scalar, so that (despite the tt((@)) flag) the subscript +picks the first character. ) item(tt("${${(@)foo}[1]}"))( -The produces the result tt(b). In this case, the inner substitution +The produces the result tt(bar). In this case, the inner substitution tt("${(@)foo}") produces the array tt(LPAR()bar baz)tt(RPAR()). The outer -substitution tt("${...[1]}"), however, has no array flag, so that it joins -the array it has to a single word and indexes as if it were a string. Note -that this is not identical to the case tt("${foo[1]}"), since here the -expression tt(foo[1]) is recognised immediately as an index into an array, -so that the result in that case is tt(bar). +substitution tt("${...[1]}") detects that this is an array and picks the +first word. This is similar to the simple case tt("${foo[1]}"). ) enditem() -- Peter Stephenson Tel: +39 050 844536 WWW: http://www.ifh.de/~pws/ Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy