From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2535 invoked from network); 29 Jun 2000 15:41:20 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 29 Jun 2000 15:41:20 -0000 Received: (qmail 20366 invoked by alias); 29 Jun 2000 15:35:33 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3234 Received: (qmail 20326 invoked from network); 29 Jun 2000 15:35:09 -0000 From: "Bart Schaefer" Message-Id: <1000629153121.ZM7765@candle.brasslantern.com> Date: Thu, 29 Jun 2000 15:31:20 +0000 In-Reply-To: <000101bfe1c0$86504080$21c9ca95@mow.siemens.ru> Comments: In reply to "Andrej Borsenkow" "Local variables in sourced scripts" (Jun 29, 3:52pm) References: <000101bfe1c0$86504080$21c9ca95@mow.siemens.ru> X-Mailer: Z-Mail (5.0.0 30July97) To: "Andrej Borsenkow" , "ZSH users mailing list" Subject: Re: Local variables in sourced scripts MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 29, 3:52pm, Andrej Borsenkow wrote: } Subject: Local variables in sourced scripts } } Am I the only one who finds it useful? I'd really appreciate them in rc } scripts - I always forget to unset temporary variables there and no fear } to clobber some existing ones ... You can't have it both ways. In shell functions all variables are local unless either explicitly declared global (with "typeset -g", and that only works in 3.1.6+) or assigned-to without declaring. The problem is that you can't create any variables other than plain scalars and simple arrays without declaring them. If you make variables local to rc files, then all declarations of integers, floats, associative arrays, unique arrays ("typeset -U"), etc. must use -g, which will probably break every nontrivial .zshrc on the planet (I know it'd screw mine up big time). } Related question - I think, local functions were at least discussed } sometimes. What is current status? You can make a function with local scope, but only if it has the same name as another function with global scope. Like this: zmodload -i zsh/parameter function uselocalfn { local -A +h functions eval "function localfn { echo this is the $1 local function }" localfn } zagzig[104] localfn zsh: command not found: localfn zagzig[105] uselocalfn first this is the first local function zagzig[106] localfn this is the first local function zagzig[107] uselocalfn second this is the second local function zagzig[108] localfn this is the first local function This happens because the `functions' parameter has its value restored by individual assignment to each associative array element. Consequently, only elements that existed before the local copy was created have their old value restored; newly-created elements do not get erased. Of course it's incredibly inefficient to redefine every global function every time you want to use a single local function, so this probably is in serious need of improvement. Another side-effect is that when the global value of $functions is restored, every autoloaded (aka undefined) function turns into a defined function. They still work as if they're autoloaded, thanks to the magic of "autoload -X", but they no longer are flagged as undefined. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net