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

Re: Proof of concept: "static" parameter scope



On Wed, 30 Sep 2015 17:27:48 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> torch% disable -r local
> torch% zxxx() { local x=(a b c); print $x }
> torch% 
> 
> Eh?  Why is that not a syntax error?  The reserved word "local" has
> been disabled, yet x=(a b c) is still parsed as an assignment.

What would make it a syntax error here?  You haven't disabled globbing
flags.  It's only an error when you run it and get...

> torch% zxxx
> zxxx: number expected

It's just the same as

% zyyy() { burble x=(a b c); print $x }
% zyyy
zyyy: number expected

as it should be.  Maybe you'd forgotten that parentheses are parsed so
as not to make white space work as a word separator?

> Enabling the builtin again does not fix this:
> 
> torch% enable -r local
> torch% zxxx
> zxxx: number expected

Obviously, since it parsed the function zxxx when local wasn't a
reserved word and you've done nothing to reparse it.  You need to parse
it again.

% enable -r local
% zxxx() { local x=(a b c); print $x }  
% zxxx
a b c

This is the point of the difference between reserved words (keywords that
cause parsing to behave differently) and builtins (names of commands that
are looked up when the command is about to be executed).

This certainly doesn't help you make a syntactic structure dynamically
loadable, but that's always going to be hairy.  I think our choices are
- document it and live with it
- decide it's too hairy and limit ourselves to autoloading an option to
local etc.
- provide adequate means, probably turned on by default, to load everything
early enough that it just works.  This means the distribution would enable
"private", or whatever, as a keyword out of the box.  If we don't I don't
think this is worth doing.  (Of course you can still use disable -r in am
initialisation file.)
- go a step even further than that and just compile it in (but you can *still*
disable -r).
- or, I suppose, we could compile it in with disable -r applied, but then
we're back with all the gotchas about needing to reparse if you use it.

pws



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