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

Re: ${a[(i)pattern]} if a=()



On Mar 16,  2:40pm, Stephane Chazelas wrote:
} Subject: ${a[(i)pattern]} if a=()
}
} Hiya,
} 
} $ zsh -f -c 'a=(b); echo ${a[(i)a]}'
} 2
} $ zsh -f -c 'a=(); echo ${a[(i)a]}'
} 0
} 
} Shouldn't the above return 1?

Hmm ... it seems it has always returned zero when the array is empty.
It would seem to make more sense for it to return 1, but I'm worried
there are other unforseen consequences.
 
What changed is zsh-workers/23562, which made it an error to treat a
zero subscript the same as 1 (see the thread leading up to 23562 and
the related thread ending in 23440).

Naturally we had code relying on the old behavior and didn't find all
of those cases.

} That at leasts causes compinstall to fail

The following will work around the above issue to fix that:

--- compinstall.~1.11.~	2008-02-11 20:25:13.000000000 -0800
+++ compinstall	2008-03-16 10:17:55.000000000 -0700
@@ -1438,7 +1438,7 @@
 	 done
 	 amenu=(${=menu})
 	 elt=${amenu[(i)*select*]}
-	 [[ $elt -gt $#amenu ]] && elt=
+	 [[ $elt -eq 0 || $elt -gt $#amenu ]] && elt=
 	 case $select in
 	   <->) if [[ -n $elt ]]; then
 		  amenu[$elt]="select=$select"



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