I've determined in hindsight that the $_ variable exposed in the<[ xquery expr ]> is not right.
This concatenates all positional parameters into a single sequence. If any of the positional parameters are a sequence > 1 then the result loses information. For example
set <[ 1,2,3 ]> 4 5
echo <[ $_ ]>
Very non obvious. The fact that $1 is a sequence has been lost and the $_ is a concatenation of 1,2,3,4,5
To fix this I now predeclare distinct variables $_1 $_2 ... for all positional parameters.
This preserves the sequences in the positional parameters.
$ echo <[ $_1 ]>
1 2 3
This means you can access all positional parameters within the <[ ]> expression with no loss of fidelity. I'd like to get rid of $_ as it is now redundant. However someone might be using it ... so I'm keeping it in for now.
A side effect of this, however, is that there is no way to access $# within the <[ ]> or to iterate over all positional parameters in one query. This is a fundamental limit of xquery and XDM which do not allow nested sequences. It also means that if you actually assign a global variable _1 then it is overwritten by the positional parameter $1 within the <[ ]> expression.
So is it too late now that I've published "1.0" of xmlsh ? Even if there is efficiency and usability issues ? Would anyone be affected ?
I have no idea because I have no metrics of how much xmlsh is being used ....
which gets to my next post ...