Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Memory leak when working with undefined associative array keys & problems with unset



Bart Schaefer wrote on Sat, 23 Sep 2017 18:48 -0700:
> On Sep 23,  6:59pm, Peter Stephenson wrote:
> } > } $ unset "a[$key]"
> } > } unset: a[hello * [ world]: invalid parameter name
> } > 
> } > Hmm, when examining ${a[$key]} we enter parse_subscript() with $key
> } > tokenized, but there's no way to get the tokenized string to reach
> } > the same point in the unset builtin
> } 
> } I gave up on this ages ago, frankly.  We certainly a need way of raw key
> } reference, but I don't think we've got one, and each time we tweak it we
> } seem to make it even more tortuous.
> 
> The basic problem is that a[$key]=foo is parsed in assignment context,
> but unset a[$key] is parsed in ordinary word context.  I don't see any
> way around this other than either making unset a keyword, or adding a
> command-line option to unset as Daniel suggested.  Neither of these
> alternatives makes me very happy.

We could also invent a separate builtin, "zunset".  That way we avoid stomping
on any options POSIX's 'unset' might grow in the future.

This way, scalars, which are standard, are unset by 'unset' which too is standard,
and assocs, which are non-standard, are unset by 'zunset' which too is non-standard.

> As noted, ksh93 has (had?) also thrown up its hands on this one.



Messages sorted by: Reverse Date, Date, Thread, Author