From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4944 invoked from network); 14 Jun 1998 06:42:53 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 14 Jun 1998 06:42:53 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id CAA27187; Sun, 14 Jun 1998 02:39:28 -0400 (EDT) Resent-Date: Sun, 14 Jun 1998 02:37:41 -0400 (EDT) From: "Bart Schaefer" Message-Id: <980613233827.ZM30068@candle.brasslantern.com> Date: Sat, 13 Jun 1998 23:38:27 -0700 In-Reply-To: <002801bd9750$a021f600$cde8ec82@a205.ryd.student.liu.se> Comments: In reply to "=?iso-8859-1?Q?Johan_Sundstr=F6m?=" "Static variables?" (Jun 14, 6:55am) References: <002801bd9750$a021f600$cde8ec82@a205.ryd.student.liu.se> X-Mailer: Z-Mail (5.0.0 30July97) To: =?iso-8859-1?Q?Johan_Sundstr=F6m?= , "Zsh-list" Subject: Re: Static variables? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"LU-uh1.0.-d6.q-sWr"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1615 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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