zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: <zsh-workers@zsh.org>
Subject: Re: let unset array element remove compatible with bash
Date: Wed, 22 Feb 2012 09:28:27 -0800	[thread overview]
Message-ID: <120222092827.ZM24425@torch.brasslantern.com> (raw)
In-Reply-To: <20120222095248.1ea8140b@pwslap01u.europe.root.pri>

On Feb 22,  9:52am, Peter Stephenson wrote:
}
} So it's not simply a case of unconditionally deleting an element.  I
} think you need to check the element is present in the first place.

Is there a straightforward way to do that?  The code in subst.c that
handles ${+var[x]} is rather convoluted, and every combination of
getvalue()/fetchvalue() that I've tried always returns non-NULL for
subscripted expressions.

Which probably explains this comment in subst.c:

    /*
     * Indicates we have tried to get a value in v but that was
     * unset.  I don't quite understand why (v == NULL) isn't
     * good enough, but there are places where we seem to need
     * to second guess whether a value is a real value or not.
     */
    int vunset = 0;

Then there's this horror, which appears to be fetching the entire
array to call arrlen() on it, just to discover whether one of the
elements is not set:

	    /* Value retrieved from parameter/subexpression is scalar */
	    if (v->pm->node.flags & PM_ARRAY) {
		/*
		 * Although the value is a scalar, the parameter
		 * itself is an array.  Presumably this is due to
		 * being quoted, or doing single substitution or something,
		 * TODO: we're about to do some definitely stringy
		 * stuff, so something like this bit is probably
		 * necessary.  However, I'd like to leave any
		 * necessary joining of arrays until this point
		 * to avoid the multsub() horror.
		 */
		int tmplen = arrlen(v->pm->gsu.a->getfn(v->pm));

		if (v->start < 0)
		    v->start += tmplen + ((v->flags & VALFLAG_INV) ? 1 : 0);
		if (!(v->flags & VALFLAG_INV) &&
		    (v->start >= tmplen || v->start < 0))
		    vunset = 1;
	    }

Gaah.


  reply	other threads:[~2012-02-22 17:28 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPg-njyehwyETKY4KGdFV8u_ZwkMku-G9xVi7d7PpU9rZhdPDA@mail.gmail.com>
2012-02-22  5:01 ` Bart Schaefer
2012-02-22  9:52   ` Peter Stephenson
2012-02-22 17:28     ` Bart Schaefer [this message]
2012-02-22 20:19       ` Peter Stephenson
2012-07-01 16:53         ` PATCH " Bart Schaefer
2012-07-01 18:15           ` Peter Stephenson
2012-07-01 22:23             ` Bart Schaefer
2012-07-02  9:11               ` Peter Stephenson
2012-07-07 17:02                 ` Bart Schaefer
2012-07-08 17:50                   ` Peter Stephenson
2012-07-01 22:29             ` Bart Schaefer
2012-07-02  7:36           ` Bart Schaefer
2012-02-23 10:58       ` Peter Stephenson
2012-02-23 16:23         ` Bart Schaefer

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=120222092827.ZM24425@torch.brasslantern.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).