zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Unset and $empty[(i)] and $empty[(I)] -- worth the effort?
Date: Mon, 7 Dec 2020 15:13:24 -0800	[thread overview]
Message-ID: <CAH+w=7aQNk4g6y2NZC0skZg+1RxKZH5GAXM1Gi6PUYi58Aa27g@mail.gmail.com> (raw)

Current behavior (git master branch):

5.8.0.2-dev % print $notset[(i)] $notset[(I)]

5.8.0.2-dev % typeset emptystr
5.8.0.2-dev % print $emptystr[(i)] $emptystr[(I)]
0 0
5.8.0.2-dev % typeset -a emptyarr
5.8.0.2-dev % print $emptyarr[(i)] $emptyarr[(I)]
1 0
5.8.0.2-dev % unset emptyarr
5.8.0.2-dev % print $emptyarr[(i)] $emptyarr[(I)]

5.8.0.2-dev %

I want to rationalize $emptystr[(i)] by saying that it's searching for
an empty substring and it did find one, so it can't return
(($#emptystr + 1)), but there's not really a $emptystr[0] either.  In
the reverse direction, if an empty stubstring is allowed to match
there's no unambiguous answer for $emptystr[(I)].

Behavior on the declarednull branch:

delclarednull % print $notset[(i)] $notset[(I)]

delclarednull % typeset emptystr
delclarednull % print $emptystr[(i)] $emptystr[(I)]

delclarednull % emptystr=""
delclarednull % print $emptystr[(i)] $emptystr[(I)]
0 0
delclarednull % typeset -a emptyarr
delclarednull % print $emptyarr[(i)] $emptyarr[(I)]

delclarednull % emptyarr=()
delclarednull % print $emptyarr[(i)] $emptyarr[(I)]
1 0
delclarednull % unset emptyarr
delclarednull % print $emptyarr[(i)] $emptyarr[(I)]

delclarednull %

Given that the behavior on $emptystr is already poorly defined, I'm
not sure it makes much sense to put any effort into making the
uninitialized $emptyarr case differ from the $notset case.

Further opinions?


             reply	other threads:[~2020-12-07 23:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-07 23:13 Bart Schaefer [this message]
2020-12-23 23:04 ` Felipe Contreras
2020-12-24 19:06   ` Phil Pennock
2020-12-29 17:54     ` Felipe Contreras

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='CAH+w=7aQNk4g6y2NZC0skZg+1RxKZH5GAXM1Gi6PUYi58Aa27g@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@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).