zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane@chazelas.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users List <zsh-users@zsh.org>
Subject: Re: Why would I use .namespace.myvar?
Date: Sun, 10 Mar 2024 12:13:59 +0000	[thread overview]
Message-ID: <20240310121359.iuhmf5renmuf6y4z@chazelas.org> (raw)
In-Reply-To: <CAH+w=7ZfyjWJA2bn7s8DowcuRuArgy4o_fNP9avJidL5fL=SmA@mail.gmail.com>

2024-03-09 14:58:10 -0800, Bart Schaefer:
[...]
> >   (and not having them starting with .
> >   is discouraged, presumably because that would conflict with
> >   ksh93's compound variables which zsh might want to support in
> >   the future?)
> 
> Something like that.  Ksh has a couple of special meanings of
> ${var.func} in addition to compound variables.  It's all rather messy
> if you ask me, but we might pick and choose.

Thanks Bart for the detailed feedback!

Yes, all of the namespace, compounds, types, disciplines, nested
assoc/array in ksh93 give an "experimental" vibe and of being
unfinished and/or not fully thought through.

A lot of it is also not hugely useful in a shell, and is not
documented much and I don't expect many people have used even
half of it which likely also explains why it's still quite bogus.

I've just raised https://github.com/ksh93/ksh/issues/727 this
morning about "echo" not working in namespaces making me
thinking there can't be many people using those namespaces there
(even if we take into account that "print" is preferred over
"echo" in ksh)

See also https://github.com/ksh93/ksh/issues/325 and more
generally
https://github.com/ksh93/ksh/issues?q=is%3Aissue+is%3Aopen+namespace
there.

[...]
> That's also correct, except that -h doesn't mean the same thing at
> all, so it's not really a meaningful "even with".
> 
> > except with things like:
> >
> >   typeset -p ${(kM)parameters:#.*}
> 
> Also "typeset -pm pattern"

Thanks, that makes it significantly easier to list variables in
a namespace.

[...]
> > Is there a chance that ksh93's namespace keyword be added in the
> > future?
> 
> Yes, adding the namespace keyword is planned, probably for a
> next-after-next release when we have some more real-world usage of the
> current code.
[...]
> > Would the fact that function names have been allowing .
> > since forever or that .foo or .foo.1 are allowed not be a problem?
> 
> There's a small chance of backward-compatibility issues if someone is
> using function names beginning with a dot, yes.  Names containing a
> dot are only an issue if the part before the dot is the same as the
> name of a parameter
> 
> We'd have to make some decisions about .foo.1 and similar with respect
> to assignments -- it's not a large problem for expansions given that
>   namespace foo { echo $1; }
> "fails upward" to the positional parameter $1 if ${.foo.1} does not exist.

Would it be correct to say that the main goal for introducing
namespaces then would be to tidy-up the output of typeset -p/set
for all the subsystems of zsh written in zsh (completion,
zle...) and third party plugins?

Wouldn't having the .space.var variables and namespace {...} in
two separate releases be counter-productive as plugin authors
would first change their code from:

myplugin() {
  myplugin_myglobal=whatever
  ...
}

To:

myplugin() {
  .myplugin.myglobal=whatever
  ...
}

in 6.0 (say) as an improvement to limit the typeset output
pollution.

Only to change it again to:

myplugin() namespace myplugin {
  myglobal=whatever
  ...
}

(or however namespace is going to be meant to be used then)

In 7.0

(and possibly have to maintain 3 versions for zsh 5, 6, 7).

If it's going to be done in a staged way, it seems it would be
safer to start strict and relax later rather than the other way
round to limit the risk of breaking backward compatibility in
the future.

Like if we allow ${.space} and ${.space.1} now but we find that
it prevents adding namespace {...} in the future, it will be
harder then to say "oh you can't do that anymore".

Deferring the introduction of the "namespace" keyword (which
sounds to me like it's the key missing part for the feature to
be really useful) sounds risky unless we already have a clear
idea of how it's going to work as we might find that the whole
design and possibly user API would need to be rethought (like
the namespaces would need to be declared in advance like in
ksh93).

(having said that, I've not given it much thought myself so my
apprehensions may very well be baseless).

-- 
Stephane


  reply	other threads:[~2024-03-10 12:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-09 14:30 Stephane Chazelas
2024-03-09 22:58 ` Bart Schaefer
2024-03-10 12:13   ` Stephane Chazelas [this message]
2024-03-10 20:08     ` Bart Schaefer
2024-03-10 22:16       ` Ray Andrews
2024-03-10 22:45         ` Lawrence Velázquez
2024-03-10 23:02           ` Ray Andrews
2024-03-10 23:53             ` Mark J. Reed
2024-03-11  2:22               ` Ray Andrews
2024-03-11  2:35                 ` Bart Schaefer
2024-03-11  2:50                   ` Ray Andrews
2024-03-11  7:53               ` Stephane Chazelas
2024-03-10 22:48         ` Bart Schaefer
2024-03-10 23:14           ` Ray Andrews

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=20240310121359.iuhmf5renmuf6y4z@chazelas.org \
    --to=stephane@chazelas.org \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@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).