I'm struggling with (one of many) artifacts of allowing expressions (variables, and positional parameters) be XdmValues, which allow sequences.
In generally this is a good, if not necessary thing.
It allows sequences to be stored in variables and produced as expressions and be preserved as sequences. For example
A=<[ 1 , 2 , ]>
xquery -f file.query -v sequence_var $A
Note that you can pass a single XdmValue ($A) as a parameter to Xquery.
The problem comes if you want to 'flatten' the sequence to seperate positional params.
Example
A=$(ls) # produces a single sequence of files
echo $A
This looks right but under the hood echo is getting a single argument (argv[1]) which is a sequence.
Suppose I want to delete all these files
posix:rm $A
Ups ... rm now gets 1 argument ... it has to know that if the argument is sequence to iterate over each item like this
for i in $A ; do posix:rm $i ; done
For many commands getting sequences where they expect items is problematic.
But on the other hand being able to preserve sequences is critical.
So What to do ?
I'm working on (and open to suggestion) a syntax which forcibly flattens sequences into positional parameters.
Something like maybe
$-variable
although I'd like it to work with inline expressions as well
posix:rm $(ls) # How to get this to flatten ?
Comments welcome on this idea