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

Parameters



This was the list of things I was gathering to do with parameters.  Maybe
there's not really anything to do, but I thought I'd ask.

1.  Arrays.  As Andrej has discovered, scripts using a lot of these are
pretty inefficient because they are always allocated and freed element by
element.  You can already sort of pre-extend arrays by doing things like
arr[256]=''.  But that's not so good: you can't use arr=($arr foo) or
arr[$#arr+1]=foo to add elements, since they go in the wrong place, and
those blank elements can show up in other places, and they're all allocated
as single-byte strings, too.  So maybe we should think about allowing
arrays to keep their allocated length until they are unset, or maybe
something more complicated.

2. Retrieving parameters.  I pointed out when I introduced the mapfile
module that the shell was doing too much accessing of values, so when you
do `vared mapfile[foo]', file foo gets read twice.  This could be fixed
with an extra set of flags passed down in params.c saying the value is not
going to be used and doesn't need to be computed.  However, while it only
affects a few special parameters, most of which (those already built-in)
have farily simple definitions and don't need to be altered much, this is
probably an unnecessary lot of work.

3. vared is a bit strange with read-only variables: it lets you edit the
value, then announces after you have that it's a read-only parameter and
you can't set it.  We could deal with this two ways (1) add the phrase `So
there.' to the error message just to rub it in (2) test earlier whether it
is read-only.  I favour (2).

4. On a similar theme, non-existent associative array elements
respect the nounset option, but `vared compconfig[nonexistentelement]'
doesn't cause an error as it usually would without the -c option.  I don't
know if this is a feature or not.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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