[xsl] Use cases for sequence of sequences (Was: Re: Re: XSLT vs Perl)

Subject: [xsl] Use cases for sequence of sequences (Was: Re: Re: XSLT vs Perl)
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 4 Feb 2004 07:52:58 +0100
"Michael Kay" <mhk@xxxxxxxxx> wrote in message
> > The only feature that I really miss is a sequence that can
> > have sequences as its individual items. If this was offered
> > then one could write partial applications of functions in an
> > amazingly compact and readable way.
> It wouldn't be hard in Saxon to write a pair of extension functions
> sequence-to-item() and item-to-sequence() that wrap a sequence in a
> single item (allowing it to be included in a sequence), and unwrap it
> again. Worth experimenting with.

I'd prefer just


so that one could write:

  f:myFun( ($p1, seq($p2,p3), $p4) )


  f:curry( pmyFun, ($p1, it(()), $p4)  )

The first expression above evaluates a function f:myFun(), which accepts a
single argument, which is a sequence.

This comes very handy when we need to avoid having to define many different
overloads of the function in order to be able to apply it on different
number of arguments. Instead of defining N overloads of the function, we
define it as having a single argument, which is a sequence. Depending on how
many items there are in the sequence, the function behaves as desired and as
the corresponding overload would behave. The only problem with this is if
one of the arguments must be a sequence -- then its value cannot be
specified as an item and we'd need the seq() extension.

The second expression evaluates the curry() function -- in this case it
takes a reference to a function that accepts three arguments and the second
argument to curry is the sequence of actual values to be specified to the
first-argument-function. In this sequence of values the value for the second
argument is notably missing (the empty sequence).

The result is a new function, which is a partial application of myFun with
specified first and third arguments and is still a function of one argument
(the second argument to myFun, which still has to be specified).

The above one-line expression of curry() is visually straightforward to
understand and is probably the most compact possible.

Compare with what one has to write at present (using FXSL for XSLT 2.0):

    <xsl:variable name="vrtfCurriedMyFun">
      <xsl:call-template name="curry">
        <xsl:with-param name="pFun" select="$vMyFun"/>
        <xsl:with-param name="pNargs" select="3"/>
        <xsl:with-param name="arg1" select="$p1"/>
        <xsl:with-param name="arg3" select="$p4"/>

    <xsl:variable name="vCurriedMyFun"


Dimitre Novatchev
FXSL developer,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread