Partial applications now manipulate fnref arity
Previously, a separate `@partial' attribute was added to the ref and the `@arity' maintained. Unfortunately, this coupled `f:arity' with `f:partial', which is unnecessary, considering that partial application is supposed to conceptually yield a new function, which should be transparent to `f:arity'.master
parent
bc871435fa
commit
cd278c31d4
|
@ -98,8 +98,9 @@
|
||||||
<f:ref>
|
<f:ref>
|
||||||
<sequence select="$ref/@*" />
|
<sequence select="$ref/@*" />
|
||||||
|
|
||||||
<attribute name="partial"
|
<!-- the arity of the new partial application -->
|
||||||
select="count( $argout )" />
|
<attribute name="arity"
|
||||||
|
select="$arity - $argn" />
|
||||||
|
|
||||||
<sequence select="$ref/*" />
|
<sequence select="$ref/*" />
|
||||||
</f:ref>
|
</f:ref>
|
||||||
|
@ -128,8 +129,7 @@
|
||||||
<!-- we never want to fail, so we perform our type check here rather
|
<!-- we never want to fail, so we perform our type check here rather
|
||||||
than using param/@as -->
|
than using param/@as -->
|
||||||
<sequence select="$fn instance of element(f:ref)
|
<sequence select="$fn instance of element(f:ref)
|
||||||
and exists( $fn/@partial )
|
and exists( $fnref[ 2 ] )" />
|
||||||
and number( $fn/@partial ) gt 0" />
|
|
||||||
</function>
|
</function>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,16 +135,12 @@
|
||||||
<variable name="ref" as="element( f:ref )"
|
<variable name="ref" as="element( f:ref )"
|
||||||
select="$fnref[ 1 ]" />
|
select="$fnref[ 1 ]" />
|
||||||
|
|
||||||
|
<!-- this implicitly asserts on the type; it should never fail if
|
||||||
|
the system is being used properly -->
|
||||||
<variable name="arity" as="xs:integer"
|
<variable name="arity" as="xs:integer"
|
||||||
select="$ref/@arity" />
|
select="$ref/@arity" />
|
||||||
|
|
||||||
<variable name="partial" as="xs:integer"
|
<sequence select="$arity" />
|
||||||
select="if ( $ref/@partial ) then
|
|
||||||
$ref/@partial
|
|
||||||
else
|
|
||||||
0" />
|
|
||||||
|
|
||||||
<sequence select="$arity - $partial" />
|
|
||||||
</function>
|
</function>
|
||||||
|
|
||||||
</stylesheet>
|
</stylesheet>
|
||||||
|
|
|
@ -51,11 +51,9 @@
|
||||||
<param name="args" select="()" />
|
<param name="args" select="()" />
|
||||||
</call>
|
</call>
|
||||||
|
|
||||||
<expect label="returns FNREF"
|
<expect label="returns reference to original target"
|
||||||
test="$x:result[ 1 ] = $fnref" />
|
test="f:QName( $x:result[ 1 ] )
|
||||||
|
= f:QName( $fnref )" />
|
||||||
<expect label="indicates that 0 arguments were partially applied"
|
|
||||||
test="$x:result/@partial = 0" />
|
|
||||||
|
|
||||||
<expect label="returns nothing else"
|
<expect label="returns nothing else"
|
||||||
test="count( $x:result ) = 1" />
|
test="count( $x:result ) = 1" />
|
||||||
|
@ -68,12 +66,13 @@
|
||||||
<param name="args" select="$args/foo:a, $args/foo:b" />
|
<param name="args" select="$args/foo:a, $args/foo:b" />
|
||||||
</call>
|
</call>
|
||||||
|
|
||||||
<expect label="returns FNREF as first item in sequence"
|
<expect label="returns target reference as first item in
|
||||||
test="$x:result[ 1 ] = $fnref" />
|
sequence"
|
||||||
|
test="f:QName( $fnref )
|
||||||
<expect label="indicates that N arguments were partially applied"
|
= f:QName( $x:result[ 1 ] )" />
|
||||||
test="$x:result/@partial = 2" />
|
|
||||||
|
|
||||||
|
<!-- FIXME: this breaks the abstraction; use opaque
|
||||||
|
introspection -->
|
||||||
<expect label="returns each argument, ordered"
|
<expect label="returns each argument, ordered"
|
||||||
test="$x:result[ 2 ] is $args/foo:a
|
test="$x:result[ 2 ] is $args/foo:a
|
||||||
and $x:result[ 3 ] is $args/foo:b" />
|
and $x:result[ 3 ] is $args/foo:b" />
|
||||||
|
@ -108,8 +107,10 @@
|
||||||
<param name="args" select="$args/foo:b" />
|
<param name="args" select="$args/foo:b" />
|
||||||
</call>
|
</call>
|
||||||
|
|
||||||
<expect label="returns FNREF as first item in sequence"
|
<expect label="returns target reference as first item in
|
||||||
test="$x:result[ 1 ] = $fnref" />
|
sequence"
|
||||||
|
test="f:QName( $fnref )
|
||||||
|
= f:QName( $x:result[ 1 ] )" />
|
||||||
|
|
||||||
<expect label="returns arguments from both partial applications"
|
<expect label="returns arguments from both partial applications"
|
||||||
test="count( $x:result ) = 3" />
|
test="count( $x:result ) = 3" />
|
||||||
|
@ -406,7 +407,9 @@
|
||||||
|
|
||||||
|
|
||||||
<!-- caller may extract the function ref from the sequence and
|
<!-- caller may extract the function ref from the sequence and
|
||||||
assert on that -->
|
assert on that; we are going to explicitly choose to *not*
|
||||||
|
support that behavior, since an fnref acquires meaning as an
|
||||||
|
opaque unit -->
|
||||||
<scenario label="given a valid fref, partially applied with N>0
|
<scenario label="given a valid fref, partially applied with N>0
|
||||||
arguments, without argument sequence">
|
arguments, without argument sequence">
|
||||||
<call function="f:is-partial">
|
<call function="f:is-partial">
|
||||||
|
@ -414,8 +417,8 @@
|
||||||
select="f:partial( foo:ternary(), (1, 2) )[ 1 ]" />
|
select="f:partial( foo:ternary(), (1, 2) )[ 1 ]" />
|
||||||
</call>
|
</call>
|
||||||
|
|
||||||
<expect label="returns true()"
|
<expect label="returns false()"
|
||||||
test="$x:result = true()" />
|
select="false()" />
|
||||||
</scenario>
|
</scenario>
|
||||||
</scenario>
|
</scenario>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue