From: "Bart Schaefer" <schaefer@brasslantern.com>
To: "Johan Sundström" <johsu650@student.liu.se>,
Zsh-list <zsh-users@math.gatech.edu>
Subject: Re: Static variables?
Date: Sat, 13 Jun 1998 23:38:27 -0700 [thread overview]
Message-ID: <980613233827.ZM30068@candle.brasslantern.com> (raw)
In-Reply-To: <002801bd9750$a021f600$cde8ec82@a205.ryd.student.liu.se>
On Jun 14, 6:55am, =?iso-8859-1?Q?Johan_Sundstr=F6m?= wrote:
} Subject: Static variables?
}
} Is it possible to use c-style "static" variables in my functions, or do I
} have to stick to global ones?
The only "persistent" variable namespace is the global one.
That said, there may be a way to get the effect you want, because the
"local" namespace has dynamic scope. Here's how:
First, rename your precmd as precmd_body.
Next, create a function precmd_setup which assigns values to the variables
you wish to make static.
Now create a new precmd which does the following:
- Declares "local" all the variables that are assigned in precmd_setup
- Executes precmd_setup (this assigns to the locals of precmd)
- Executes precmd_body (this references the locals of precmd)
- Redefines precmd_setup to assign the new values of the locals to
the appropriate names, e.g. eval function precmd_setup \{ ... \}
Finally, be sure that none of the affected variables is declared local
in precmd_body (so it will inherit the locals from precmd).
The tricky bit is "redefines precmd_setup." Depending on the values of
the variables in question, it may be difficult to generate on the fly a
new definition that performs the correct assignments. Just how ugly are
the contents of the variables you're trying to preserve?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
prev parent reply other threads:[~1998-06-14 6:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-06-14 4:55 Johan Sundström
1998-06-14 6:38 ` Bart Schaefer [this message]
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=980613233827.ZM30068@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=johsu650@student.liu.se \
--cc=zsh-users@math.gatech.edu \
/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).