Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: 3.1.5-pws-6 + assorted: Doc for local parameter scope
- X-seq: zsh-workers 5258
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: PATCH: 3.1.5-pws-6 + assorted: Doc for local parameter scope
- Date: Thu, 4 Feb 1999 22:23:53 -0800
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author