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

Re: Proof of concept: "static" parameter scope

On Mon, Sep 28, 2015 at 7:04 PM, Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> Bart wrote:
>> The patch below creates a module "zsh/param/static" which supports a
>> single builtin command "static".  The included doc section describes
>> "static" in detail, but briefly, it works like the "local" builtin
>> except that variables so declared are not dynamically visible to any
>> called functions.
> Very nice.
>> "Called functions" includes recursive calls to the function itself, so
>> this doesn't work like C "static".  Therefore I'm in the market for a
>> better name.
> The trouble with "static" is that people with a C or C++ background will
> expect something different. It might be better to find a new word in the
> thesaurus that doesn't carry the baggage of another common meaning. Note
> that, as you mention in the documentation patch, ksh93 has a typeset
> -S option which does do C like static variables. Aside from confusing
> users, the Zsh use of the term "parameter" seems even more tenuous when
> applied to lexically scoped variables because they can't be used as
> named parameters. So instead of "static" I would simply suggest "var".
> This name does take the emphasis away from the scope but that could be a
> good thing in terms of encouraging it's use. It is actually "local" with its
> obscure dynamic scoping that really needs the more elaborate explanation
> in the documentation. And "typeset" isn't a good name because
> typesetting evokes things like LaTeX.

I think the "local" scope is actually extremely simple to understand,
it goes out of scope when the current function ends, period. In C it
is much more complicated, it goes out of scope when you leave a block,
it goes out of scope when you call a function but then goes back into
scope when you return, possibly multiple times, you can 'goto' out and
in to scope. I suppose it's also a matter of perspective.

Also, "static" already means at least 3 different things in C, it
doesn't make any sense to expect it to mean any particular one of
these things in zsh?

What about "private" instead of static though? If the intention is to
hide it from called functions, it is somewhat closer to that concept,
if not just the normal word.

Mikael Magnusson

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