zsh-users
 help / color / mirror / code / Atom feed
From: Roman Perepelitsa <roman.perepelitsa@gmail.com>
To: Sebastian Gniazdowski <sgniazdowski@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: What's the reasoning behind z & s returning nular for empty input?
Date: Sat, 9 Nov 2019 08:50:46 +0100	[thread overview]
Message-ID: <CAN=4vMpj91iZzOgLNNcUzb4UuTDEAiFxkjyuAa76hqqaQjnFBg@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVCD7e=vATDBc7px1d4XNYiKu1=2iZP9YaJ5PutgsDTsoQ@mail.gmail.com>

On Sat, Nov 9, 2019 at 8:27 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hi
> arr=( "${(s:,:):-}" )
> print -r ${#arr} ${(q)arr}
> Output: 1 ''

This makes sense. Consider how many elements we should get when
splitting a string on commas:

    split ",,," => 4 elements
    split ",," => 3 elements
    split "," => 2 elements
    split "" => ???

The last split could give either 1 element or 0. The former is
consistent with the rest, the latter is not.

> arr=( "${(z):-}" )
> print -r ${#arr} ${(q)arr}
> Output: 1 ''

This is a bug IMO. Let's again consider how many elements we should
get when tokenizing different strings:

    tokenize "a a a a" => 4 elements
    tokenize "a a a" => 3 elements
    tokenize "a a" => 2 elements
    tokenize "a" => 1 element
    tokenize "" => ???

Consistency requires that the last line gives zero elements. If it
gave one empty element, it would be the only case where (z) can
produce empty elements.

Here's another way to put it. For any array x,
"${(@z)${(j::)${(@q)x}}}" expands to "${(@q)x}", except when x is
empty. The special case is an inconsistency.


Roman.

  reply	other threads:[~2019-11-09  7:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-09  7:26 Sebastian Gniazdowski
2019-11-09  7:50 ` Roman Perepelitsa [this message]
2019-11-09  7:52   ` Roman Perepelitsa
2019-11-09  8:11   ` Sebastian Gniazdowski
2019-11-09  8:22     ` Roman Perepelitsa
2019-11-09  8:40       ` Sebastian Gniazdowski
2019-11-09  8:52         ` Roman Perepelitsa
2019-11-09  9:09           ` Sebastian Gniazdowski
2019-11-09 14:33       ` 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='CAN=4vMpj91iZzOgLNNcUzb4UuTDEAiFxkjyuAa76hqqaQjnFBg@mail.gmail.com' \
    --to=roman.perepelitsa@gmail.com \
    --cc=sgniazdowski@gmail.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).