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

Re: LOCAL_VARS option ?



On Thu, 19 Jan 2017 06:54:08 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Phil suggested on IRC a LOCAL_VARS option that has the effect of making
> all newly-declared variables local; e.g.,
> 
> % unset x y
> % () { setopt localvars; x=42; typeset -g y=43 }
> % echo $+x $+y
> 0 1
> % 
> 
> I'm attaching a proof of concept patch (work in progress; see top of the
> attachment for known issues), but WDYT of the the general concept?

It does seem useful --- it's very easy to forget to make variables
local, while usually only a small fraction ever need to make their way
out of functions (there are special cases of function suites like
completion which behave diffierently).  I'm worried that picking up all
the places where the flag needs setting or unsetting could be a huge
job.

> +em(TODO): should tt(emulate -L) set tt(LOCAL_VARS)?

That's going to be too big a change to the current behaviour, I think.
Not enough people know about WARN_CREATE_GLOBAL / typeset -g which would
have prepared them for this behaviour, and it's going to have very
obscure effects on nested functions.  It clearly needs flagging up under
emulate -L either way.

pws



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