Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_DKIM_INVALID
	autolearn=ham autolearn_force=no version=3.4.0
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=brasslantern-com.20150623.gappssmtp.com; s=20150623;
        h=from:message-id:date:in-reply-to:comments:references:to:subject
         :mime-version:content-type;
        bh=ceNjJDt+5fIWbo+8T/fylDpo/H9T2cm6oGnxboxodp4=;
        b=H2AYxFbxnxKW87RrZo9uwggeNpT6M7+Yn/xZ/242xbgPv1cvcXP2YBO9XZHT+cioUM
         pOcmJsH98dktJo7bIL3dtmmpNBXoZMMODDZjgfFAdKEBOEVfNdIpHm4llSlU+6qU84Ys
         Nn3cf9V/lBbQq1uN+cF/R2d5CUqNxC5n8Rt1GfSHw1cGZ09bYf4vOezS03BBdUtCebdL
         yqToWu0gfY+PrSuZXFarPnjEgwt3+gwNBXbPCAVXOgf5dLQb4a0queqO+7Ns72DKkuWb
         pweUWf6F/D09ZwiliwPrLbQTRUlye5QADouV+PoynpytOyDD3nS/90gEUmuCzsLCH+by
         SMvA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:message-id:date:in-reply-to:comments
         :references:to:subject:mime-version:content-type;
        bh=ceNjJDt+5fIWbo+8T/fylDpo/H9T2cm6oGnxboxodp4=;
        b=EmqbmsPNfCH7gMxCP64Q0pWDcHD8R0ng8OycltSHynRu2qLyl9swDu2vDFsZ7aEGvH
         iz/mxJdm5FlUaxEw2m+PKRi/d05OdzN6wjQqIiCNf2+YqfX9F7gDGIHiO9ckiPfrP45Q
         p26GXOSPI04ElgOn/CDIa+Hgcd7VgIfPEDrKEMY9z8NemOpLQud2Z/ufpcdyULRmsjuU
         goisJi/AGj2P0BfSmtpFookEI2Ym2H8pQlZTZRBQ0wEyKjPj/hMVcZb/oTrarp8xLQmv
         GOImFEdld5haAy8D458/FztqlacwwNLryLth6nc1XPNbUWBmTB7FFJEG5wr7E8pMcfpX
         8Rxg==
X-Gm-Message-State: AG10YORCKugGGwY6p18NGX9OfSCnQCWI7ZZTgeulNyC8F5NLepsuJXvVaivE6P6Q4UkS6A==
X-Received: by 10.98.10.81 with SMTP id s78mr39563867pfi.119.1453868070721;
        Tue, 26 Jan 2016 20:14:30 -0800 (PST)
From: Bart Schaefer <schaefer@brasslantern.com>
Message-Id: <160126201513.ZM2538@torch.brasslantern.com>
Date: Tue, 26 Jan 2016 20:15:13 -0800
In-Reply-To: <20160126225008.GA4731@tarsus.local2>
Comments: In reply to Daniel Shahaf <d.s@daniel.shahaf.name>
        "Re: [PATCH] typeset: set $? on incidental error" (Jan 26, 10:50pm)
References: <20160123235300.GC20278@tarsus.local2>  <56A445E0.50706@gmx.com> 
	<20160126225008.GA4731@tarsus.local2>
X-Mailer: OpenZMail Classic (0.9.2 24April2005)
To: zsh-workers@zsh.org
Subject: Error status of "repeat" (was Re: [PATCH] typeset: set $? on incidental error)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Seq: zsh-workers 37804

On Jan 26, 10:50pm, Daniel Shahaf wrote:
}
} What would you expect "repeat 0+++ (exit 42)" to set $? to?

In fact what it does set $? to, is 0.

}        repeat WORD do LIST done
}               WORD is expanded and treated as an arithmetic expression, which
}               must evaluate to a number N.  LIST is then executed N times.

Hmm, this doesn't actually appear to happen.

torch% x=1+3
torch% repeat x print -n Z
torch% repeat $x print Z
Z
torch% 

So it's just peeling the first thing that looks like a number off the
WORD and repeating that many times, or zero times if WORD is not a number.

BUT!  Even if we change the code --


diff --git a/Src/loop.c b/Src/loop.c
index 4def9b6..61dad09 100644
--- a/Src/loop.c
+++ b/Src/loop.c
@@ -493,7 +493,7 @@ execrepeat(Estate state, UNUSED(int do_exec))
     tmp = ecgetstr(state, EC_DUPTOK, &htok);
     if (htok)
 	singsub(&tmp);
-    count = atoi(tmp);
+    count = mathevali(tmp);
     pushheap();
     cmdpush(CS_REPEAT);
     loops++;


-- that doesn't change the exit status!

torch% repeat 0+++ (exit 42)
zsh: bad math expression: lvalue required
torch% print $?
0

Next question: Do I commit that patch?

