zsh-workers
 help / color / mirror / code / Atom feed
From: Ronald Fischer <ynnor@mm.st>
To: Peter Stephenson <p.stephenson@samsung.com>, zsh-workers@zsh.org
Subject: Re: Bug in regexp operator when warn_create_global is in effect
Date: Mon, 06 Feb 2017 16:48:10 +0100	[thread overview]
Message-ID: <1486396090.3153023.871899752.700E33C7@webmail.messagingengine.com> (raw)
In-Reply-To: <20170206120215.1942a506@pwslap01u.europe.root.pri>

> The main point is to handle cases something like the following, where
> although the variable creation is hidden it's explicitly requested by the
> user:
> 
> fn() {
>    [[ $1 = (#m)${~2} ]]
> }
> 
> That (#m) in the pattern and the fact the pattern is in a function are
> the only relevant facts here.  The (#m) is a request to cause MATCH,
> MBEGIN and MEND to be set by the shell.  Because that's the purpose of
> (#m), you want the warning so as to be able to decide whether those
> variables are to be global or not and resolve between the two with a
> local or typeset -g.
> 
> Your case is different because the use of the variables isn't requested
> by special syntax, it's buried under standard regex syntax, so I've
> fixed it for that one case.  I'm certainly interested in any more like
> this you come up with.

Now I get it! Thanks for the explanation!

This (#m) example makes me think to the following problem (looks like an
opened can of worms): 

Clearly, a user who is aware to the global-vs-local topic will
conciously decide, whether he wants the M* variables local or global,
but no matter how he decides, it would be an insane decision if he
doesn't decide for the same scope on all three variables. For example,
it doesn't make sense to define MBEGIN as global and MATCH and MEND as
local. From the programmer's viewpoint, it would be more natural to
either decide on these three variables "as a group". Either all global
or all local. Currently, there is nothing which would enforce this
decision.

This now looks like a special case for (#m), but I wonder whether the
same wouldn't be true too for zsh modules, which also might create sets
of variables which belong together.

>From a programmer's viewpoint, a good concept (IMHO) would be that these
automatically created variables are always local, so if a function wants
to make a match globally visible, it would have to create its own global
variable for this. In the same way, it would perhaps make sense that
loop variables (in for-loop) are by default local, because this is the
usual way to use them. However, in both cases this might break existing
code, so it is perhaps not a real alternative. Seems that we have to
live with a compromise.

> That's fixed by my patch, as far as I can tell with no collateral
> damage. 

Thanks a lot, really. From which zsh version will this be available?

Ronald


  reply	other threads:[~2017-02-06 15:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170202073801epcas4p3fa77b3bbe2794d2f574ac0319f13ab3f@epcas4p3.samsung.com>
2017-02-02  7:37 ` Ronald Fischer
2017-02-02  9:43   ` Peter Stephenson
2017-02-02 22:55     ` Bart Schaefer
2017-02-03  9:20       ` Peter Stephenson
2017-02-06 10:44     ` Ronald Fischer
2017-02-06 11:11       ` Peter Stephenson
2017-02-06 11:26         ` Ronald Fischer
2017-02-06 12:02           ` Peter Stephenson
2017-02-06 15:48             ` Ronald Fischer [this message]
2017-02-06 16:04               ` Peter Stephenson

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=1486396090.3153023.871899752.700E33C7@webmail.messagingengine.com \
    --to=ynnor@mm.st \
    --cc=p.stephenson@samsung.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).