Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: What's the reasoning behind z & s returning nular for empty input?
- X-seq: zsh-users 24411
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- Subject: Re: What's the reasoning behind z & s returning nular for empty input?
- Date: Sat, 9 Nov 2019 08:50:46 +0100
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=v30dGqxIkflj3N2HAJyELFZAGgJjmGps4Oe7enGRKFM=; b=sSllgyAHUpVb51f4tcXM3VeNjulP0tI+UGbb4u+1yPpU8NqixJcXzo5n1xbuj8eOna faOh05fNDXAL3unPAhkumV6iEZW+p4xTto4aFzPsY4lkGpGgzwl8DMclgmwwpm0kfNxQ PswcwJXR/VhHwaBBD1Uwolxz9UX2MEH5atdtzYnI6d1R98wvxxdsFPvp0OUH9+KNFQRu ISErRLFdtXpnC4oYmQlpoJmuh/A8bLY55QHZH3WoO05+n5nV+fKvvZCxi0UFseHMTPlB vqkNtLap/JoEj/4LMf51QrU179jEw493K6+Frafdykei1LCiWhXd/s0m+09qXz0I6jBU Y1uA==
- In-reply-to: <CAKc7PVCD7e=vATDBc7px1d4XNYiKu1=2iZP9YaJ5PutgsDTsoQ@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCD7e=vATDBc7px1d4XNYiKu1=2iZP9YaJ5PutgsDTsoQ@mail.gmail.com>
On Sat, Nov 9, 2019 at 8:27 AM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> 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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author