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
Mike Gerwitz 2014-11-30 03:29:46 -05:00
parent bc871435fa
commit cd278c31d4
3 changed files with 25 additions and 26 deletions

View File

@ -98,8 +98,9 @@
<f:ref>
<sequence select="$ref/@*" />
<attribute name="partial"
select="count( $argout )" />
<!-- the arity of the new partial application -->
<attribute name="arity"
select="$arity - $argn" />
<sequence select="$ref/*" />
</f:ref>
@ -128,8 +129,7 @@
<!-- we never want to fail, so we perform our type check here rather
than using param/@as -->
<sequence select="$fn instance of element(f:ref)
and exists( $fn/@partial )
and number( $fn/@partial ) gt 0" />
and exists( $fnref[ 2 ] )" />
</function>

View File

@ -135,16 +135,12 @@
<variable name="ref" as="element( f:ref )"
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"
select="$ref/@arity" />
<variable name="partial" as="xs:integer"
select="if ( $ref/@partial ) then
$ref/@partial
else
0" />
<sequence select="$arity - $partial" />
<sequence select="$arity" />
</function>
</stylesheet>

View File

@ -51,11 +51,9 @@
<param name="args" select="()" />
</call>
<expect label="returns FNREF"
test="$x:result[ 1 ] = $fnref" />
<expect label="indicates that 0 arguments were partially applied"
test="$x:result/@partial = 0" />
<expect label="returns reference to original target"
test="f:QName( $x:result[ 1 ] )
= f:QName( $fnref )" />
<expect label="returns nothing else"
test="count( $x:result ) = 1" />
@ -68,12 +66,13 @@
<param name="args" select="$args/foo:a, $args/foo:b" />
</call>
<expect label="returns FNREF as first item in sequence"
test="$x:result[ 1 ] = $fnref" />
<expect label="indicates that N arguments were partially applied"
test="$x:result/@partial = 2" />
<expect label="returns target reference as first item in
sequence"
test="f:QName( $fnref )
= f:QName( $x:result[ 1 ] )" />
<!-- FIXME: this breaks the abstraction; use opaque
introspection -->
<expect label="returns each argument, ordered"
test="$x:result[ 2 ] is $args/foo:a
and $x:result[ 3 ] is $args/foo:b" />
@ -108,8 +107,10 @@
<param name="args" select="$args/foo:b" />
</call>
<expect label="returns FNREF as first item in sequence"
test="$x:result[ 1 ] = $fnref" />
<expect label="returns target reference as first item in
sequence"
test="f:QName( $fnref )
= f:QName( $x:result[ 1 ] )" />
<expect label="returns arguments from both partial applications"
test="count( $x:result ) = 3" />
@ -406,7 +407,9 @@
<!-- 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
arguments, without argument sequence">
<call function="f:is-partial">
@ -414,8 +417,8 @@
select="f:partial( foo:ternary(), (1, 2) )[ 1 ]" />
</call>
<expect label="returns true()"
test="$x:result = true()" />
<expect label="returns false()"
select="false()" />
</scenario>
</scenario>