zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: unexpected unmodified variable
Date: Thu, 6 Oct 2022 21:36:33 -0700	[thread overview]
Message-ID: <CAH+w=7ZtkgMZFGgZwe4mLbS3LceHsPvH6a8hBBdPAoS6iW0g8w@mail.gmail.com> (raw)
In-Reply-To: <0bc658a2-3941-82f5-2433-d105f31db09a@eastlink.ca>

On Thu, Oct 6, 2022 at 6:37 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Playing with that, it seems the last math operation gets to be the rv
> unless you set a return value

Yes, that's documented.  Interpreting the argument of "return" counts
as a math operation, so the math value of a "functions -M" function
really is always the last math operation.

> ... I had : "return 3" active, but commenting it out didn't seem to
> change anything which is puzzling.

I think you must have typo'd something somewhere.  Add "functions -t
func2" so you can see a trace of what's executing.

>  Anyway, it seems that 'count' can be
> a normal variable just so long as 'func2' is called mathematically.

That's not exactly the point ... what kind of variable "count" is, in
this case, doesn't matter.  What matters is that $(( func2() )) runs
in the current shell, not in a subshell.

In case it wasn't obvious, $(( func2 )) treats func2 as the name of a
variable, not a function, so it doesn't run func2 at all.


  reply	other threads:[~2022-10-07  4:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 19:07 Ray Andrews
2022-10-06 19:28 ` Peter Stephenson
2022-10-06 21:58   ` Ray Andrews
2022-10-07  0:36     ` Bart Schaefer
2022-10-07  1:37       ` Ray Andrews
2022-10-07  4:36         ` Bart Schaefer [this message]
2022-10-07 15:28           ` Ray Andrews
2022-10-07 20:00             ` Bart Schaefer
2022-10-07 21:59               ` Ray Andrews

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='CAH+w=7ZtkgMZFGgZwe4mLbS3LceHsPvH6a8hBBdPAoS6iW0g8w@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@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).