From: Philippe Altherr <philippe.altherr@gmail.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: [PATCH] Fix ERR_EXIT behavior in function calls and "always" statements
Date: Tue, 22 Nov 2022 03:52:45 +0100 [thread overview]
Message-ID: <CAGdYchvM8uwvQ9B-S4n_-oMQkNqgZZrqG9jwYCV7Nz+5Lo6Q=w@mail.gmail.com> (raw)
In-Reply-To: <230a78bb-fa97-4f3a-94a2-86982316274b@app.fastmail.com>
[-- Attachment #1: Type: text/plain, Size: 3912 bytes --]
>
> Each time though, you've removed the NEWS item. Although we've
> established that the behavior it describes was not actually
> appropriate, there still has been a change in ERR_EXIT behavior that
> probably warrants a mention. What's the best description of that?
Good point. There is indeed a behavior change but it's more complicated
than what you described. I will try to come up with something. Actually my
3 fix patches address 3 different issues. In my opinion, at least 2 of them
qualify as bugs but it still makes sense to describe what changes.
This suggests that anonymous
> functions should *not* behave like normal function calls here.
That's debatable. If, like me, you see anonymous functions as some kind of
syntactic sugar, then it makes sense that they behave like function calls
and exit. However, I can also understand that others rather see them as
another type of compound command. In that case, they should not exit.
To help decide what to do, here is a table that lists all the different
cases and how they behave in the current Zsh, in a patched Zsh, and in a
patched Zsh where anonymous functions behave as compound commands:
Code Current Zsh Patched Zsh
Compound command (and patches)
A) false Exit Exit Exit
B) false && true No exit No exit No exit
C) { false && true } No exit No exit No exit
D) () { false } Exit Exit Exit
E) () { false && true } Exit Exit *No
exit*
F) () { { false && true } } No Exit *Exit* No
exit
G) f() { false }; f Exit Exit Exit
H) f() { false && true }; f Exit Exit Exit
I) f() { { false && true } }; f No Exit *Exit* *Exit*
Currently anonymous functions behave like function calls. My patches don't
change that but they change/fix cases F and I to behave as mandated by
POSIX. If anonymous functions are changed to behave like compound commands
then anonymous functions behave as if the code was inlined. This changes
the behavior of case E, which currently exits.
Is the compound command behavior a reasonable one? Certainly yes. Is it
desirable? I guess that's more debatable. Personally, I am leaning towards
the current behavior. I could be convinced otherwise and for sure I could
live with the alternative.
If you care about code complexity (of the Zsh implementation), then that
would be an argument against the compound command option as it requires
additional code. However, in my opinion, languages should in general NOT be
designed to simplify their implementation but rather to simplify their
usage.
Does it? These seem to behave identically with Philippe's latest
> patches; am I overlooking something?
No, with my patch "false && true" and "{ false && true}" now always behave
the same.
Frankly I'm
> still not certain that the extra level of { } should matter in the
> function example.
With my patches, they no longer do. Note however that the behaviors of the
following examples, which are unaffected by my patches:
set -e
> { false && true } # does not exit
> () { false && true } # exits
As you can see, with my patches, an extra level of { } no longer changes
any behavior. However, already today, anonymous functions don't always
behave the same as the inlined code.
FYI: Here are my next steps
- Write NEWS for my 3 fixes.
- Better document the role and usage of noerrexit and this_noerrexit.
- Try to fix "eval", "source", and possibly a bunch of other related cases.
Unless anyone sees a reason not to, it would be nice to submit my first
pacth, which reverts Bart's changes. For the other patches, I have at the
very least to first add a NEWS item.
Philippe
[-- Attachment #2: Type: text/html, Size: 6168 bytes --]
next prev parent reply other threads:[~2022-11-22 2:53 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 14:40 Philippe Altherr
2022-11-19 13:39 ` Philippe Altherr
2022-11-21 0:43 ` Bart Schaefer
2022-11-21 7:22 ` Lawrence Velázquez
2022-11-22 2:52 ` Philippe Altherr [this message]
2022-11-22 4:51 ` Bart Schaefer
2022-11-22 10:17 ` Peter Stephenson
2022-11-23 8:11 ` Lawrence Velázquez
2022-11-23 6:59 ` Lawrence Velázquez
2022-11-23 9:43 ` Philippe Altherr
2022-11-23 16:11 ` Bart Schaefer
2022-11-23 20:57 ` Submitting multiple patches (was: Re: [PATCH] Fix ERR_EXIT behavior in function calls and "always" statements) Daniel Shahaf
2022-11-23 21:11 ` Bart Schaefer
2022-11-23 21:22 ` Bart Schaefer
2022-11-23 21:54 ` Bart Schaefer
2022-11-24 2:21 ` Philippe Altherr
2022-11-26 2:28 ` Bart Schaefer
2022-11-26 4:02 ` Philippe Altherr
2022-11-24 1:47 ` [PATCH] Fix ERR_EXIT behavior in function calls and "always" statements Philippe Altherr
2022-11-24 4:28 ` Lawrence Velázquez
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='CAGdYchvM8uwvQ9B-S4n_-oMQkNqgZZrqG9jwYCV7Nz+5Lo6Q=w@mail.gmail.com' \
--to=philippe.altherr@gmail.com \
--cc=larryv@zsh.org \
--cc=schaefer@brasslantern.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).