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

Re: Disabling null elision (was: Re: Most Recent File)

On Mon, Oct 25, 2021 at 9:45 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> Roman Perepelitsa wrote on Sun, Oct 24, 2021 at 09:22:46 +0200:
> > > It's one of the nice things about zsh that you can use the shorter
> > $foo and $#foo instead of "${foo[@]}" and ${#foo[@]}. I wish there was
> > an option to disable null elision with a corresponding expansion flag
> > to turn it on similar to no_sh_word_split and ${(=)name}
> I'm in two minds about this.
> On the one hand, null elision breaks the principle of least surprise —
> both in reference to other programming languages, and in reference to
> SH_WORD_SPLIT's default behaviour being the unlike-Bourne-shell
> behaviour.
> On the other hand, making it on by default would be backwards
> incompatible, and making it off by default would mean there's yet
> another syntax-changing option for everyone to keep in mind when they
> review random autoloaded functions' code.

How about a two-step approach with the possibility of stopping after the first?

Step 1: Add an option to disable null elision. Off by default.
Step 2: Make this option the default in native mode.

I would be 99% satisfied with step 1. I would be less satisfied if
step 2 was implemented because I hate when my scripts break. Granted,
even step 1 will break "plugins" that attempt to work with any options
but at least it won't break executable scripts. It's also nice that
this option would affect parsing, only evaluation, so it won't be
necessary to care about it when defining functions.

I do get your point about the difficulty of reading plugins when you
have to keep in mind all possible options that the code can be
evaluated with (how many plugins work with no_glob? mine don't). I
still think it's worth it to have *this* option. Dropping all those
quotes would remove noise from code and make comprehension easier. I
realise that few users would benefit from this. Not many write zsh
scripts to begin with and a small number of those would enable a new


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