From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4203 invoked by alias); 13 May 2011 21:37:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29266 Received: (qmail 880 invoked from network); 13 May 2011 21:37:45 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.212.43 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=gPN0EgrjWAtY487xQydLxwvDWLFBxwN1zrf3Drynnyo=; b=IUpxwlcDsj5Vhqmw3O/R5HEskJ3s8aUStt0+1AAMpVKgFppQ2Qe7/2D+GgIzFkcmUp ehR9aJRGpdR+NQ08eapp7pTnHvmqODNcxVxunAi2bBUps+PWRfe5abeAaeTug7DQLo6G ck/nL4G0NSPf17Gar3e/g4RjcqeGxnVa5etTI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=WNUfzw+1ZVt/xPM9sAa3nIfAdATnPBiNq1/CW+9l2V5hRaqzZens0c7ln940AiEQZW i4gaESSGsuAp4nBZj1UstEvWGMdo0b0N+VH6e0nRm3WjkVylfeE9un72avP/vqv9U2Dc hillDca0+ILUgRauwB/cG44r9CaQxfznAFXf0= MIME-Version: 1.0 Date: Fri, 13 May 2011 23:37:37 +0200 Message-ID: Subject: Infinite recursions in math evaluation From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 I was trying to do something completely different and noticed that this causes an infinite recursion: a=a; ${(#)a} and this doesn't ${(#):-a} (and surprised me by cding into my first $cdpath entry, turns out it returned a null character, and that does that with autocd on.) The thing seems to be the variable name having the same name as the value of it. Aha, actually a=a; $(( a )) crashes in the same way. (On a machine with a presumably less optimized/buggy compile, it does print "zsh: math recursion limit exceeded" instead of crashing). Is it simply a user error? I wouldn't expect either of these expressions to recursively look up values of the parameter until it encountered a number, but this is indeed what happens: % a=b; b=c; c=d; d=e; e=f; f=5; echo $(( a )) 5 bash does the same... It seems to be of somewhat random utility though: a='b c' b='5 +' c='5*3' echo $(( a )) zsh: bad math expression: operator expected at `c' a='b+c' echo $(( a )) zsh: bad math expression: operand expected at `' b='55+32' echo $(( a )) 102 I scanned quickly through the "Arithmetic Evaluation" section and found nothing suggesting that this should happen. It is also perhaps somewhat unclear from the description of the (#) flag in the manpage that it causes the same eval as in $(( )), it simply says the resulting words are parsed as numeric expressions. Executing echo ${(#):-'foo=bar, bar=65, foo'} twice outputs A the second time btw. I would not be opposed to just describing this behaviour in the manpage (if I didn't just miss a huge section that describes it again.. :) -- Mikael Magnusson PS What I originally actually wanted to run was $(( #a )), but I remembered the wrong syntax.