xsl-list
[Top] [All Lists]

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

2004-02-03 23:52:58

"Michael Kay" <mhk(_at_)mhk(_dot_)me(_dot_)uk> wrote in message
news:001301c3ea99$fd0190e0$6401a8c0(_at_)pcukmka(_dot_)(_dot_)(_dot_)
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

      seq()
and
      it()

so that one could write:

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

and

  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:call-template>
    </xsl:variable>

    <xsl:variable name="vCurriedMyFun"
                  select="$vrtfCurriedMyFun/*"/>


Cheers,

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



<Prev in Thread] Current Thread [Next in Thread>