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: local but persistent integer?
Date: Fri, 16 Sep 2022 14:41:29 -0700	[thread overview]
Message-ID: <CAH+w=7bV-8to91BSHYJyESPTcNQh-guSXunKrsrhBGeO4D7yBQ@mail.gmail.com> (raw)
In-Reply-To: <b1a20d70-bf98-04f4-e401-9521152d03cd@eastlink.ca>

On Fri, Sep 16, 2022 at 12:43 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> On 2022-09-16 10:44, Bart Schaefer wrote:
> > On Fri, Sep 16, 2022 at 8:19 AM Ray Andrews <rayandrews@eastlink.ca> wrote:
> >>           integer -x start="$(( $(date +%s%N)/1000000 ))"
> >>
> >> ... I need 'start' to persist between function calls which it does
> > Given that construct, it should not.
>
> ... so it's visible externally as you say, but it's not going away either.

Hm, this is possibly a bug, but it's also possibly an expected
side-effect of "export" that I've forgotten about.  My previous
statement is correct for string-scalars created with "typeset" and
"local" etc., but "integer" behaves differently.  I think this is
related to preserving the attributes of the variable (i.e., even if
unset, it remains an integer, so if you assign to it again it acts
like one) about which I believe I recall some discussion, but I don't
recall when it was implemented.

In any case it's not reliable to expect locally-declared variables to
behave this way, and I'd still recommend using -g or -gH instead of
-x.


  reply	other threads:[~2022-09-16 21:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16 15:19 Ray Andrews
2022-09-16 17:44 ` Bart Schaefer
2022-09-16 19:43   ` Ray Andrews
2022-09-16 21:41     ` Bart Schaefer [this message]
2022-09-16 21:50       ` Ray Andrews
2022-09-17  1:51       ` 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=7bV-8to91BSHYJyESPTcNQh-guSXunKrsrhBGeO4D7yBQ@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).