[Bug 21597] higher-order-functions-068

https://www.w3.org/Bugs/Public/show_bug.cgi?id=21597

Abel Braaksma <abel.braaksma@xs4all.nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |abel.braaksma@xs4all.nl

--- Comment #1 from Abel Braaksma <abel.braaksma@xs4all.nl> ---
I finally had some time to look more deeply into this. I agree that the
function as written contains errors. It was a rewrite of the following example:

<xsl:function name="f:fibcont" as="xs:integer">
    <xsl:param name="n" as="xs:integer" />
    <xsl:param name="cont" as="function(xs:integer) as xs:integer" />
    <xsl:sequence select="
            if($n le 1) then $cont(1)
            else f:fibcont($n - 2, function($a as xs:integer) as xs:integer {
                f:fibcont($n - 1, function($b as xs:integer) as xs:integer {
                    $cont($a + $b)
                })
            })

        "/>
</xsl:function>

which should be called with an identity function. However, the error in the
test was not apparent because it is the same error the above function gets
(i.e. "Required item type of second argument of anonymous function is
function(*)"), which led me to trying to write it correctly while ignoring the
error. In the above function, there is no anonymous function that takes
function(*) as second argument, so the error is either misleading or wrong (or
I made a typo again ;)).

I think that the above version is a more readable way of writing the CPS
version of the Fibonacci algorithm and I think it should work in XSLT 3.0. I
checked this version with the 2-argument cpsFunc JavaScript example here:
http://www.eriwen.com/javascript/cps-tail-call-elimination/, which I will copy
below in case of linkrot:

function cpsFib(n, _return) {
    if (n <= 1) {
        return _return(1);
    } else {
        return cpsFib(n-2, function(a) {
            return cpsFib(n-1, function(b) {
                return _return(a+b);
            });
        });
    }
}

I will also try to correct the $first/$second style version of the same CPS
function, but without ability to test it, it's hard to write it correctly. The
reasoning behind that rewrite was to find a way to express it in XPath/XSLT
without having errors.

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Wednesday, 15 January 2014 16:39:45 UTC