zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: Proof of concept: "static" parameter scope
Date: Sat, 3 Oct 2015 20:19:36 +0100	[thread overview]
Message-ID: <20151003201936.29b52aa4@ntlworld.com> (raw)
In-Reply-To: <150930172748.ZM3986@torch.brasslantern.com>

On Wed, 30 Sep 2015 17:27:48 -0700
Bart Schaefer <schaefer@brasslantern.com> 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


  reply	other threads:[~2015-10-03 19:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25  2:23 Bart Schaefer
2015-09-25  9:15 ` Peter Stephenson
2015-09-26  5:23   ` Bart Schaefer
2015-09-30 19:38   ` Peter Stephenson
2015-10-01  0:27     ` Bart Schaefer
2015-10-03 19:19       ` Peter Stephenson [this message]
2015-10-03 23:43         ` Autoloaded keywords (Re: Proof of concept: "static" parameter scope) Bart Schaefer
2015-10-05 21:55         ` Proof of concept: "static" parameter scope Daniel Shahaf
2015-10-05 22:17           ` Bart Schaefer
2015-10-05 22:36             ` Daniel Shahaf
2015-10-05 23:01               ` Bart Schaefer
2015-10-06  8:40           ` Peter Stephenson
2015-09-28 17:04 ` Oliver Kiddle
2015-09-28 17:58   ` Roman Neuhauser
2015-09-29 23:31     ` Andrew Janke
2015-09-30  3:06       ` Bart Schaefer
2015-09-28 19:42   ` Mikael Magnusson
2015-09-29  1:23     ` Bart Schaefer
2015-09-29  8:39       ` Peter Stephenson
2015-09-29 22:34       ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151003201936.29b52aa4@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).