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

Re: A way to untie -T vars?



On 1/23/23, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, Jan 23, 2023 at 1:47 AM Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
>>
>> Here foo is array-local-tag-tied-unique-hide-hideval. I believe it can
>> be untied and become array-local-tag-unique-hide-hideval (only "tied"
>> is gone).
>
> Hm.
>
> Another interesting note, "typeset -x" implies "-g" but "local -x" does
> not.

There's no way it could imply it, since local -g doesn't accept -g, so
you would have to argue why typeset -x should not imply it (and do it
like 30 years ago) :).

Checked the manpage and it says export is equivalent to typeset -gx,
which is true, but we could save a byte by removing that g.

Also local says this:
  Same  as  typeset,  except that the options -g, and -f are not permitted.  In
  this case the -x option does not force the use of -g, i.e. exported variables
  will be local to functions.

which does not seem to be true; typeset -x does not force -g, it is
implied by default but you can use +g to disable it again:

% bar=outside; () { typeset -x +g bar=baz; env | grep bar=baz }; echo $bar
bar=baz
outside

without the +g, the second line output is "baz" (obviously).

The entry for typeset itself correctly states:
  If the option GLOBAL_EXPORT is set, this implies the option -g,
unless  +g is also explicitly given; in other words the parameter is
not made local to the enclosing function.  This is for  compatibility
with previous versions of zsh.

Not sure if it's worth clarifying the point under "local"?

Also for maximum confusion, GLOBAL_EXPORT doesn't affect the behavior
of "export", that always forces (not implies) both -x and -g:
% export +x foo
export: bad option: +x
% export +g foo
export: bad option: +g
but with GLOBAL_EXPORT unset, my example above prints "outside" on the
second line even without the +g.

-- 
Mikael Magnusson




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