May now partially apply partial applications

master
Mike Gerwitz 2014-11-24 15:41:32 -05:00
parent 8ba1f04147
commit a02865d8b1
3 changed files with 38 additions and 5 deletions

View File

@ -39,21 +39,33 @@
the dynamic function calls will handle currying/partial application
for you, which has a much more inviting syntax.
TODO: Accept partial application as FNREF.
Partially applied functions may continue to be partially applied
until their parameters are exhausted. This can be used to implement
currying.
-->
<function name="f:partial">
<param name="fnref" as="element(f:ref)" />
<param name="fnref" as="item()+" />
<param name="args" as="item()*" />
<!-- perform type check here, not above, since we can be passed a
sequence (e.g.a partially applied function) -->
<variable name="ref"
as="element(f:ref)"
select="$fnref[ 1 ]" />
<f:ref>
<sequence select="$fnref/@*" />
<sequence select="$ref/@*" />
<attribute name="partial"
select="count( $args )" />
<sequence select="$fnref/*" />
<sequence select="$ref/*" />
</f:ref>
<!-- include any previously applied arguments (if we're partially
applying a partial application) -->
<sequence select="remove( $fnref, 1 )" />
<!-- nested sequences are implicitly flattened, so we're not
returning a sub-sequence here -->
<sequence select="$args" />

View File

@ -94,6 +94,27 @@
<expect label="returns all arguments"
test="count( $x:result ) = 4" />
</scenario>
<!-- partial applications should behave as their own functions -->
<scenario label="partially applying partial application">
<call function="f:partial">
<param name="fnref" select="f:partial( $fnref, (1, 2) )" />
<param name="args" select="3" />
</call>
<expect label="returns FNREF as first item in sequence"
test="$x:result[ 1 ] = $fnref" />
<expect label="returns arguments from both partial applications"
test="count( $x:result ) = 4" />
<expect label="arguments are ordered with previous applications
first in sequence"
test="$x:result[ 2 ] = 1
and $x:result[ 3 ] = 2
and $x:result[ 4 ] = 3" />
</scenario>
</scenario>

@ -1 +1 @@
Subproject commit 3dc0ab2e1b78dae5d31c228c22a7dd8868d5678f
Subproject commit 20c6b8a32f37a6511698fe89b78b82fd1aa64bd2