Sunday, March 21, 2010

xmlsh 1.0.3

Released xmlsh 1.0.3 today.

This includes

  • enhancements to xgetopts
  • enhancements to XML Servlet (headers and parameters)
  • new command httpsession to get/set session parameters
  • Many bug fixes
  • {expr} syntax in command line arguments to preserve sequences

Sunday, March 7, 2010

When are sequences too much ?

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