zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Cc: Michael Greenberg <michael@greenberg.science>
Subject: Re: `return` does not behave properly under `!`
Date: Wed, 7 Dec 2022 16:16:20 +0000 (GMT)	[thread overview]
Message-ID: <576947410.2118097.1670429780069@mail.virginmedia.com> (raw)
In-Reply-To: <20221207160113.ol3lcbm6p7xu3rru@chazelas.org>

> On 07/12/2022 16:01 Stephane Chazelas <stephane@chazelas.org> wrote:
> I can't see why one would call ! return if not to expect that to
> have an effect on the exit status.

I agree with Michael's argument that shows that logically it
can't have an effect on the status, whatever you want.  The return
happens immediately, so the effect of any status within the function
is not taken into account.  It's not actually any more use adding a
! in front than using

return $?
(( ! $? ))

Even if the ! had an effect, it would just be on the effect of
falling off the end, which you've explicitly told it you don't want.
I suppose a more precise parallel would be

{
  true
  return $?
} always {
  return (( !$? ))
}

which returns 0 as the second return comes too late to affect
the return status.

pws


  reply	other threads:[~2022-12-07 16:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-06 18:18 Michael Greenberg
2022-12-07  4:53 ` Bart Schaefer
2022-12-07  8:42 ` Stephane Chazelas
2022-12-07 15:05   ` Michael Greenberg
2022-12-07 16:01     ` Stephane Chazelas
2022-12-07 16:16       ` Peter Stephenson [this message]
2022-12-07 17:06         ` Bart Schaefer
2022-12-07 17:21           ` Peter Stephenson
2022-12-07 18:51             ` Bart Schaefer
2022-12-07 17:10       ` Michael Greenberg
2022-12-09 15:22         ` Michael Greenberg
2022-12-09 16:21           ` Bart Schaefer
2022-12-09 19:20             ` Michael Greenberg
2022-12-07 16:08     ` Bart Schaefer

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=576947410.2118097.1670429780069@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=michael@greenberg.science \
    --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).