From mboxrd@z Thu Jan 1 00:00:00 1970 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes From: "Bart Schaefer" Message-Id: <990204222353.ZM20944@candle.brasslantern.com> Date: Thu, 4 Feb 1999 22:23:53 -0800 X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@sunsite.auc.dk Subject: PATCH: 3.1.5-pws-6 + assorted: Doc for local parameter scope MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailing-List: 5258 The doc currently says: ... `unset' can be used to delete a parameter while it is still in scope; this will reveal the next outer parameter of the same name. This is not the case and hasn't been for some while. Try: zsh% function scope() { x=y; local x=z; unset x; echo $+x } zsh% scope 0 There's also a bug in the caveats for special parameters; they don't merely "remain special when unset." They can't be made local at all. Happily, "tied" parameters created by "typeset -T" appear to deal properly with scoping: zsh% tied() { foo=(x y z); local foo; foo=ABC; echo $FOO ; FOO=1:2:3 } zsh% typeset -T FOO foo ; tied ; echo $foo x:y:z 1 2 3 Note that assigning to the local foo did not change the global FOO, but that assigning to the global FOO _did_ change the global foo. This opens up some very interesting possibilities for stupid zsh tricks. Index: Doc/Zsh/params.yo =================================================================== --- params.yo 1998/12/16 10:00:53 1.5 +++ params.yo 1999/02/05 06:11:56 @@ -40,7 +40,8 @@ (Parameters are dynamically scoped.) The tt(typeset) builtin, and its alternative forms tt(declare), tt(integer), tt(local) and tt(readonly) (but not tt(export)), can be used to declare a parameter as being local -to the innermost scope. +to the innermost scope. Note that em(special) parameters cannot be made +local. When a parameter is read or assigned to, the innermost existing parameter of that name is used. (That is, the @@ -49,9 +50,8 @@ causes it to be created in the em(outer)most scope. Local parameters disappear when their scope ends. -tt(unset) can be used to delete a parameter while it is still in scope; this -will reveal the next outer parameter of the same name. However, em(special) -parameters are still special when unset. +tt(unset) can be used to delete a parameter while it is still in scope; +any outer parameter of the same name remains hidden. texinode(Array Parameters)(Positional Parameters)(Local Parameters)(Parameters) sect(Array Parameters) The value of an array parameter may be assigned by writing: -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com