zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Budi <budikusasi@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: How to have function local variable but must behave just a simple one
Date: Sat, 26 Aug 2023 10:34:23 +0300	[thread overview]
Message-ID: <CAN=4vMr9UjvPAJNRW8i6xviCwy-aLTb+oKoO3Y+Y-wnYzGLc7w@mail.gmail.com> (raw)
In-Reply-To: <CAH0GyZAfvds3Ztby301R+3dp0WuFWNn=0bLAQ+h5Stvp4z9tOQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 456 bytes --]

On Sat, 26 Aug 2023 at 10:26, Budi <budikusasi@gmail.com> wrote:

> How to have function local variable but must behave just a simple /
> plain variable which is retaining its value all the time, no matter
> how many times exit and enter the function


Sort of like a function-scoped static variable in C?

    int counter() {
      static int n = 0;
      return ++n;
    }

Zsh doesn't have the equivalent. You'll have to use a global parameter.

Roman.

[-- Attachment #2: Type: text/html, Size: 1389 bytes --]

  reply	other threads:[~2023-08-26  7:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-26  7:25 Budi
2023-08-26  7:34 ` Roman Perepelitsa [this message]
2023-08-26 20:26   ` Bart Schaefer
2023-08-26 20:38     ` Ray Andrews
2023-08-26 20:58       ` Roman Perepelitsa
2023-08-26 21:10         ` Ray Andrews
2023-08-26 21:13           ` Roman Perepelitsa
2023-08-27  0:50           ` Budi

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='CAN=4vMr9UjvPAJNRW8i6xviCwy-aLTb+oKoO3Y+Y-wnYzGLc7w@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=budikusasi@gmail.com \
    --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).