From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: break/continue vs. try-always
Date: Sun, 8 Jun 2014 18:54:01 +0100 [thread overview]
Message-ID: <20140608185401.35bed78f@pws-pc.ntlworld.com> (raw)
In-Reply-To: <140606232250.ZM23057@torch.brasslantern.com>
On Fri, 06 Jun 2014 23:22:50 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> I don't understand what "return -r" would do.
This would allow a sandbox inside a function; otherwise you couldn't
prevent the user skipping out early, and if you can't put a sandbox
inside a function the whole concept is degraded in a fairly major way.
I notice, however, that "return -r" is currently not an error. That's
because it's "return $(( - $r ))", which is entirely valid for zsh (but
not other shells), even though a negative status isn't valid. That
slightly gums up the normal option parsing in any case, but it looks
like it's long-standing behaviour:
% r=-1
% fn() { return -r; }
% fn
% print $?
1
So we need a syntax plan B. Variables are possible --- we already do
stuff with TRY_BLOCK_ERROR, and the code I have working is likewise
specific to "always" blocks.
Anyway, actual functioning code with a change made before I noticed that:
% which fn
fn () {
{
print Before return.
return
print After return.
} always {
print In always block.
return -r
}
print Evil plan by user to return early defeated.
}
% fn
Before return.
In always block.
Evil plan by user to return early defeated.
Hmm... along the lines of TRY_BLOCK_ERROR, and as negative numbers
aren't useful... how about... TRY_BLOCK_RETURN is by default negative,
but gets set to >= 0 if user signals a return; "always" block can set it
to some other value, one option would be to negative to prevent the return...? This also means you can force a return from the end of the always block.
> } Actually, break -r (or break 0) would have a side
> } effect on continue because of the interaction between the "breaks" and
> } "contflag" variables, so arguably break -r and continue -r shouldn't be
> } independent however it's implemented.
>
> There may already be a conflict there, e.g.
>
> while print one; do
> while print two; do
> while print three; do
> { break 2 } always { continue 3 }
> done
> done
> done
>
> In fact if there are both a "break" and a "continue" in the try-always,
> the effect is as if "continue" were called with the larger loop count,
> no matter which of them appears in the try vs. the always blocks.
>
> So we should probably define those semantics before we figure out what
> a value of 0 (or whatever) means.
Yes, indeed. The minutiae of the standard may or may not be of some
help.
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
next prev parent reply other threads:[~2014-06-08 18:01 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-04 2:12 Oddball output from zerrmsg() Bart Schaefer
2014-06-05 5:37 ` [PATCH] " Bart Schaefer
2014-06-05 15:53 ` break/continue vs. try-always Bart Schaefer
2014-06-06 20:58 ` Peter Stephenson
2014-06-06 21:08 ` Bart Schaefer
2014-06-06 21:45 ` Peter Stephenson
2014-06-07 6:22 ` Bart Schaefer
2014-06-08 17:54 ` Peter Stephenson [this message]
2014-06-08 18:41 ` Bart Schaefer
2014-06-08 19:43 ` Peter Stephenson
2014-06-08 20:29 ` Peter Stephenson
2014-06-08 21:01 ` Bart Schaefer
2014-06-08 21:50 ` Peter Stephenson
2014-06-09 2:11 ` Bart Schaefer
2014-06-12 19:35 ` Peter Stephenson
2014-06-13 6:57 ` Bart Schaefer
2014-06-13 9:55 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140608185401.35bed78f@pws-pc.ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).