Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: let unset array element remove compatible with bash
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author