Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "typeset -p" and no_GLOBAL_EXPORT, other misc.



On Tue, Mar 12, 2024 at 1:49 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
>
> IMO, typeset -g should only mean: don't make it local, do not
> instantiate a new variable in the current scope.

As I think I mentioned elsewhere, zsh's "typeset -g" (in the absence
of -p) only applies to newly instantiated parameters -- it will still
find parameters in the current (or enclosing) scope if they already
exist.  Which typically means it creates a parameter in the outermost
scope, but I suppose also answers some of my other questions, e.g., +p
-g should still find everything including locals and is not
necessarily equivalent to -p +g.

> bash-5.3$ f() { local i; integer i=2+2; echo "$i"; }
> bash-5.3$ f
>
> bash-5.3$ echo $i
> 4
>
> That "integer" changed the type of the global (outer-most) i
> variable instead of that of its caller.

Looks like "integer" et al. in bash actually search for the parameter
using the type (which corresponds to what zsh attempts to do when
using -p), rather searching for the parameter name and then altering
the type (which zsh without my patch sometimes does by accident).

Does it always use outermost scope or does it just use the "nearest"
integer (in this example) that it finds?

> In zsh, readonly var, when not emulating other shells is more
> like typeset -r:

It should in fact be exactly like "typeset -r", and export should be
exactly like "typeset +x".

> ksh93 does static scoping

As someone else pointed out elsewhere, this depends on whether you do
  foo() { ...; }
or
  function foo { ...; }
but really, I don't care, as we don't emulate this bit anyway.

Aside:  Shouldn't IGNORE_CLOSE_BRACES be set in ksh emulation?  It
currently is not.




Messages sorted by: Reverse Date, Date, Thread, Author