Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Abel Braaksma <abel.braaksma@xs...>  20130206 03:14:50
Attachments:
Message as HTML

When I define the following continuation version of the Fibonacci sequencein XSLT 3: <xsl:function name="f:fib"> <xsl:param name="n" as="xs:integer" /> <xsl:param name="countfun" as="function(*)" /> <xsl:sequence select=" if ($n = 1 or $n = 2) then $countfun(1) else let $first := function($x as xs:integer) as function(*) { let $second := function($y as xs:integer) as function(*) { $countfun($x + $y) } return f:fib($n  2, $second) } return f:fib($n  1, $first)" /> </xsl:function> and I call it as follows: <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> the expected result is 55. However, I receive the following error: Engine name: SaxonEE 9.4.0.4 Severity: fatal Description: Required item type of second argument of anonymous function is function(); supplied value has item type xs:integer Start location: 36:0 URL: http://www.w3.org/TR/xslt20/#errXTTE0790 The function is inspired by this snippet http://fssnip.net/eU, though other functional languages have similar examples. The idea behind the excercise is to eliminate the double recursive exit pointof the function by creating a continuation function. However, either the error is confusing(I don't see any anonymous function call with afunction argument) or something else is happening. I also tried the fully typed version, and an untyped version. Here's the fully typed variant: <xsl:function name="f:fib" as="xs:integer"> <xsl:param name="n" as="xs:integer" /> <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> <xsl:sequence select=" if ($n = 1 or $n = 2) then $countfun(1) else let $first := function($x as xs:integer) as xs:integer { let $second := function($y as xs:integer) as xs:integer { $countfun($x + $y) } return f:fib($n  2, $second) } return f:fib($n  1, $first)" /> </xsl:function> Any idea what I'm missing here, or is this perhaps an error with Saxon? Thanks, Abel 
From: Abel Braaksma <abel.braaksma@xs...>  20130206 03:14:50
Attachments:
Message as HTML

When I define the following continuation version of the Fibonacci sequencein XSLT 3: <xsl:function name="f:fib"> <xsl:param name="n" as="xs:integer" /> <xsl:param name="countfun" as="function(*)" /> <xsl:sequence select=" if ($n = 1 or $n = 2) then $countfun(1) else let $first := function($x as xs:integer) as function(*) { let $second := function($y as xs:integer) as function(*) { $countfun($x + $y) } return f:fib($n  2, $second) } return f:fib($n  1, $first)" /> </xsl:function> and I call it as follows: <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> the expected result is 55. However, I receive the following error: Engine name: SaxonEE 9.4.0.4 Severity: fatal Description: Required item type of second argument of anonymous function is function(); supplied value has item type xs:integer Start location: 36:0 URL: http://www.w3.org/TR/xslt20/#errXTTE0790 The function is inspired by this snippet http://fssnip.net/eU, though other functional languages have similar examples. The idea behind the excercise is to eliminate the double recursive exit pointof the function by creating a continuation function. However, either the error is confusing(I don't see any anonymous function call with afunction argument) or something else is happening. I also tried the fully typed version, and an untyped version. Here's the fully typed variant: <xsl:function name="f:fib" as="xs:integer"> <xsl:param name="n" as="xs:integer" /> <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> <xsl:sequence select=" if ($n = 1 or $n = 2) then $countfun(1) else let $first := function($x as xs:integer) as xs:integer { let $second := function($y as xs:integer) as xs:integer { $countfun($x + $y) } return f:fib($n  2, $second) } return f:fib($n  1, $first)" /> </xsl:function> Any idea what I'm missing here, or is this perhaps an error with Saxon? Thanks, Abel 
From: Abel Braaksma <abel.braaksma@xs...>  20130206 11:37:27
Attachments:
Message as HTML

I've rewritten the continuationpassing style function in a slightly more readable form, but the error is the same. The weird thing about this is, there is no anonymous function that takes two arguments. It is my guess that something with the closures is not going entirely the way it should: <xsl:function name="f:fib"> <xsl:param name="n" as="xs:integer" /> <xsl:param name="countfun" as="function(*)" /> <xsl:sequence select=" if ($n = 1 or $n = 2) then $countfun($n) else f:fib($n  1, function($x) { f:fib ($n  2, function($y) { $countfun($x + $y) }) })" /> </xsl:function> Thanks, Abel On 622013 4:14, Abel Braaksma wrote: > When I define the following continuation version of the Fibonacci > sequencein XSLT 3: > > <xsl:function name="f:fib"> > <xsl:param name="n" as="xs:integer" /> > <xsl:param name="countfun" as="function(*)" /> > > <xsl:sequence select=" > if ($n = 1 or $n = 2) > then $countfun(1) > else let $first := > function($x as xs:integer) as function(*) > { > let $second := function($y as xs:integer) as > function(*) > { > $countfun($x + $y) > } > return f:fib($n  2, $second) > } > return f:fib($n  1, $first)" /> > </xsl:function> > > and I call it as follows: > > <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> > > the expected result is 55. However, I receive the following error: > > Engine name: SaxonEE 9.4.0.4 > Severity: fatal > Description: Required item type of second argument of anonymous > function is function(); supplied value has item type xs:integer > Start location: 36:0 > URL: http://www.w3.org/TR/xslt20/#errXTTE0790 > > The function is inspired by this snippet http://fssnip.net/eU, though > other functional languages have similar examples. The idea behind the > excercise is to eliminate the double recursive exit pointof the > function by creating a continuation function. However, either the > error is confusing(I don't see any anonymous function call with > afunction argument) or something else is happening. > > I also tried the fully typed version, and an untyped version. Here's > the fully typed variant: > > <xsl:function name="f:fib" as="xs:integer"> > <xsl:param name="n" as="xs:integer" /> > <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> > > <xsl:sequence select=" > if ($n = 1 or $n = 2) > then $countfun(1) > else let $first := > function($x as xs:integer) as xs:integer > { > let $second := function($y as xs:integer) as > xs:integer > { > $countfun($x + $y) > } > return f:fib($n  2, $second) > } > return f:fib($n  1, $first)" /> > </xsl:function> > > > Any idea what I'm missing here, or is this perhaps an error with Saxon? > > Thanks, > Abel > > > > >  > Free NextGen Firewall Hardware Offer > Buy your Sophos nextgen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophosd2dfeb > > > _______________________________________________ > saxonhelp mailing list archived at http://saxon.markmail.org/ > saxonhelp@... > https://lists.sourceforge.net/lists/listinfo/saxonhelp 
From: Michael Kay <mike@sa...>  20130206 12:56:30
Attachments:
Message as HTML

I'll look into it when I have a little more time  I'm in in XQuery meetings today and tomorrow, and this one will require concentrated study! I suspect what is happening is that the function that the error message is talking about is an internally generated one. For example, Saxon generally handles function closures by creating an internal function with extra arguments representing the variables in the closure. Michael Kay Saxonica On 06/02/2013 11:37, Abel Braaksma wrote: > I've rewritten the continuationpassing style function in a slightly > more readable form, but the error is the same. The weird thing about > this is, there is no anonymous function that takes two arguments. It > is my guess that something with the closures is not going entirely the > way it should: > > <xsl:function name="f:fib"> > <xsl:param name="n" as="xs:integer" /> > <xsl:param name="countfun" as="function(*)" /> > > <xsl:sequence select=" > if ($n = 1 or $n = 2) > then $countfun($n) > else > f:fib($n  1, function($x) { > f:fib ($n  2, function($y) { > $countfun($x + $y) > }) > })" /> > </xsl:function> > > Thanks, > Abel > > > On 622013 4:14, Abel Braaksma wrote: >> When I define the following continuation version of the Fibonacci >> sequencein XSLT 3: >> >> <xsl:function name="f:fib"> >> <xsl:param name="n" as="xs:integer" /> >> <xsl:param name="countfun" as="function(*)" /> >> >> <xsl:sequence select=" >> if ($n = 1 or $n = 2) >> then $countfun(1) >> else let $first := >> function($x as xs:integer) as function(*) >> { >> let $second := function($y as xs:integer) as >> function(*) >> { >> $countfun($x + $y) >> } >> return f:fib($n  2, $second) >> } >> return f:fib($n  1, $first)" /> >> </xsl:function> >> >> and I call it as follows: >> >> <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> >> >> the expected result is 55. However, I receive the following error: >> >> Engine name: SaxonEE 9.4.0.4 >> Severity: fatal >> Description: Required item type of second argument of anonymous >> function is function(); supplied value has item type xs:integer >> Start location: 36:0 >> URL: http://www.w3.org/TR/xslt20/#errXTTE0790 >> >> The function is inspired by this snippet http://fssnip.net/eU, though >> other functional languages have similar examples. The idea behind the >> excercise is to eliminate the double recursive exit pointof the >> function by creating a continuation function. However, either the >> error is confusing(I don't see any anonymous function call with >> afunction argument) or something else is happening. >> >> I also tried the fully typed version, and an untyped version. Here's >> the fully typed variant: >> >> <xsl:function name="f:fib" as="xs:integer"> >> <xsl:param name="n" as="xs:integer" /> >> <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> >> >> <xsl:sequence select=" >> if ($n = 1 or $n = 2) >> then $countfun(1) >> else let $first := >> function($x as xs:integer) as xs:integer >> { >> let $second := function($y as xs:integer) as >> xs:integer >> { >> $countfun($x + $y) >> } >> return f:fib($n  2, $second) >> } >> return f:fib($n  1, $first)" /> >> </xsl:function> >> >> >> Any idea what I'm missing here, or is this perhaps an error with Saxon? >> >> Thanks, >> Abel >> >> >> >> >>  >> Free NextGen Firewall Hardware Offer >> Buy your Sophos nextgen firewall before the end March 2013 >> and get the hardware for free! Learn more. >> http://p.sf.net/sfu/sophosd2dfeb >> >> >> _______________________________________________ >> saxonhelp mailing list archived athttp://saxon.markmail.org/ >> saxonhelp@... >> https://lists.sourceforge.net/lists/listinfo/saxonhelp > > > >  > Free NextGen Firewall Hardware Offer > Buy your Sophos nextgen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophosd2dfeb > > > _______________________________________________ > saxonhelp mailing list archived at http://saxon.markmail.org/ > saxonhelp@... > https://lists.sourceforge.net/lists/listinfo/saxonhelp 
From: Michael Kay <mike@sa...>  20130206 22:32:28
Attachments:
Message as HTML

I have added this to the XSLT 3.0 test suite as test case higherorderfunctions068, and I confirm it is still failing with the current development build. The hypothesis I am exploring is that it is an interaction between function closures and tail recursion; my suspicion is that when the stackframe is reused/overwritten for the purpose of tailrecursion, the values required for the function closure are being corrupted. It's all pretty complex! Michael Kay Saxonica On 06/02/2013 03:14, Abel Braaksma wrote: > When I define the following continuation version of the Fibonacci > sequencein XSLT 3: > > <xsl:function name="f:fib"> > <xsl:param name="n" as="xs:integer" /> > <xsl:param name="countfun" as="function(*)" /> > > <xsl:sequence select=" > if ($n = 1 or $n = 2) > then $countfun(1) > else let $first := > function($x as xs:integer) as function(*) > { > let $second := function($y as xs:integer) as > function(*) > { > $countfun($x + $y) > } > return f:fib($n  2, $second) > } > return f:fib($n  1, $first)" /> > </xsl:function> > > and I call it as follows: > > <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> > > the expected result is 55. However, I receive the following error: > > Engine name: SaxonEE 9.4.0.4 > Severity: fatal > Description: Required item type of second argument of anonymous > function is function(); supplied value has item type xs:integer > Start location: 36:0 > URL: http://www.w3.org/TR/xslt20/#errXTTE0790 > > The function is inspired by this snippet http://fssnip.net/eU, though > other functional languages have similar examples. The idea behind the > excercise is to eliminate the double recursive exit pointof the > function by creating a continuation function. However, either the > error is confusing(I don't see any anonymous function call with > afunction argument) or something else is happening. > > I also tried the fully typed version, and an untyped version. Here's > the fully typed variant: > > <xsl:function name="f:fib" as="xs:integer"> > <xsl:param name="n" as="xs:integer" /> > <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> > > <xsl:sequence select=" > if ($n = 1 or $n = 2) > then $countfun(1) > else let $first := > function($x as xs:integer) as xs:integer > { > let $second := function($y as xs:integer) as > xs:integer > { > $countfun($x + $y) > } > return f:fib($n  2, $second) > } > return f:fib($n  1, $first)" /> > </xsl:function> > > > Any idea what I'm missing here, or is this perhaps an error with Saxon? > > Thanks, > Abel > > > > >  > Free NextGen Firewall Hardware Offer > Buy your Sophos nextgen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophosd2dfeb > > > _______________________________________________ > saxonhelp mailing list archived at http://saxon.markmail.org/ > saxonhelp@... > https://lists.sourceforge.net/lists/listinfo/saxonhelp 
From: Michael Kay <mike@sa...>  20130206 23:08:37
Attachments:
Message as HTML

On further investigation the tail call seems to be a red herring. In the inner inline function $second, the closure contains two variables $countfun and $x, and the slot numbers for these variable references have not been allocated (properly or at all) so values are being picked up from the wrong place. To be continued... Michael Kay Saxonica On 06/02/2013 22:32, Michael Kay wrote: > > I have added this to the XSLT 3.0 test suite as test case > higherorderfunctions068, and I confirm it is still failing with the > current development build. > > The hypothesis I am exploring is that it is an interaction between > function closures and tail recursion; my suspicion is that when the > stackframe is reused/overwritten for the purpose of tailrecursion, > the values required for the function closure are being corrupted. It's > all pretty complex! > > Michael Kay > Saxonica > > On 06/02/2013 03:14, Abel Braaksma wrote: >> When I define the following continuation version of the Fibonacci >> sequencein XSLT 3: >> >> <xsl:function name="f:fib"> >> <xsl:param name="n" as="xs:integer" /> >> <xsl:param name="countfun" as="function(*)" /> >> >> <xsl:sequence select=" >> if ($n = 1 or $n = 2) >> then $countfun(1) >> else let $first := >> function($x as xs:integer) as function(*) >> { >> let $second := function($y as xs:integer) as >> function(*) >> { >> $countfun($x + $y) >> } >> return f:fib($n  2, $second) >> } >> return f:fib($n  1, $first)" /> >> </xsl:function> >> >> and I call it as follows: >> >> <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> >> >> the expected result is 55. However, I receive the following error: >> >> Engine name: SaxonEE 9.4.0.4 >> Severity: fatal >> Description: Required item type of second argument of anonymous >> function is function(); supplied value has item type xs:integer >> Start location: 36:0 >> URL: http://www.w3.org/TR/xslt20/#errXTTE0790 >> >> The function is inspired by this snippet http://fssnip.net/eU, though >> other functional languages have similar examples. The idea behind the >> excercise is to eliminate the double recursive exit pointof the >> function by creating a continuation function. However, either the >> error is confusing(I don't see any anonymous function call with >> afunction argument) or something else is happening. >> >> I also tried the fully typed version, and an untyped version. Here's >> the fully typed variant: >> >> <xsl:function name="f:fib" as="xs:integer"> >> <xsl:param name="n" as="xs:integer" /> >> <xsl:param name="countfun" as="function(xs:integer) as xs:integer" /> >> >> <xsl:sequence select=" >> if ($n = 1 or $n = 2) >> then $countfun(1) >> else let $first := >> function($x as xs:integer) as xs:integer >> { >> let $second := function($y as xs:integer) as >> xs:integer >> { >> $countfun($x + $y) >> } >> return f:fib($n  2, $second) >> } >> return f:fib($n  1, $first)" /> >> </xsl:function> >> >> >> Any idea what I'm missing here, or is this perhaps an error with Saxon? >> >> Thanks, >> Abel >> >> >> >> >>  >> Free NextGen Firewall Hardware Offer >> Buy your Sophos nextgen firewall before the end March 2013 >> and get the hardware for free! Learn more. >> http://p.sf.net/sfu/sophosd2dfeb >> >> >> _______________________________________________ >> saxonhelp mailing list archived athttp://saxon.markmail.org/ >> saxonhelp@... >> https://lists.sourceforge.net/lists/listinfo/saxonhelp > > > >  > Free NextGen Firewall Hardware Offer > Buy your Sophos nextgen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophosd2dfeb > > > _______________________________________________ > saxonhelp mailing list archived at http://saxon.markmail.org/ > saxonhelp@... > https://lists.sourceforge.net/lists/listinfo/saxonhelp 
From: Abel Braaksma <abel.braaksma@xs...>  20130207 09:38:16
Attachments:
Message as HTML

Quite an interesting challenge it seems. If you are interested in the theory behind this type of function rewriting, it is an optimization technique to rewrite a recursive function that has two recursive exit points into a function that has one recursive exit point to allow it to be tailcall optimized. With this technique, any function can be rewritten to become tailcall optimized. In this O'Caml paper, chapter 4, there's quite a readable version of the function and an explanation of how it works: http://www.cs.rice.edu/~taha/publications/journal/gttse07.pdf Thanks for looking into it! Abel On 722013 0:08, Michael Kay wrote: > On further investigation the tail call seems to be a red herring. In > the inner inline function $second, the closure contains two variables > $countfun and $x, and the slot numbers for these variable references > have not been allocated (properly or at all) so values are being > picked up from the wrong place. To be continued... > > Michael Kay > Saxonica > > On 06/02/2013 22:32, Michael Kay wrote: >> >> I have added this to the XSLT 3.0 test suite as test case >> higherorderfunctions068, and I confirm it is still failing with >> the current development build. >> >> The hypothesis I am exploring is that it is an interaction between >> function closures and tail recursion; my suspicion is that when the >> stackframe is reused/overwritten for the purpose of tailrecursion, >> the values required for the function closure are being corrupted. >> It's all pretty complex! >> >> Michael Kay >> Saxonica >> >> On 06/02/2013 03:14, Abel Braaksma wrote: >>> When I define the following continuation version of the Fibonacci >>> sequencein XSLT 3: >>> >>> <xsl:function name="f:fib"> >>> <xsl:param name="n" as="xs:integer" /> >>> <xsl:param name="countfun" as="function(*)" /> >>> >>> <xsl:sequence select=" >>> if ($n = 1 or $n = 2) >>> then $countfun(1) >>> else let $first := >>> function($x as xs:integer) as function(*) >>> { >>> let $second := function($y as xs:integer) as >>> function(*) >>> { >>> $countfun($x + $y) >>> } >>> return f:fib($n  2, $second) >>> } >>> return f:fib($n  1, $first)" /> >>> </xsl:function> >>> >>> and I call it as follows: >>> >>> <xsl:valueof select="f:fib(10, function($a as xs:integer){$a})" /> >>> >>> the expected result is 55. However, I receive the following error: >>> >>> Engine name: SaxonEE 9.4.0.4 >>> Severity: fatal >>> Description: Required item type of second argument of anonymous >>> function is function(); supplied value has item type xs:integer >>> Start location: 36:0 >>> URL: http://www.w3.org/TR/xslt20/#errXTTE0790 >>> >>> The function is inspired by this snippet http://fssnip.net/eU, >>> though other functional languages have similar examples. The idea >>> behind the excercise is to eliminate the double recursive exit >>> pointof the function by creating a continuation function. However, >>> either the error is confusing(I don't see any anonymous function >>> call with afunction argument) or something else is happening. >>> >>> I also tried the fully typed version, and an untyped version. Here's >>> the fully typed variant: >>> >>> <xsl:function name="f:fib" as="xs:integer"> >>> <xsl:param name="n" as="xs:integer" /> >>> <xsl:param name="countfun" as="function(xs:integer) as >>> xs:integer" /> >>> >>> <xsl:sequence select=" >>> if ($n = 1 or $n = 2) >>> then $countfun(1) >>> else let $first := >>> function($x as xs:integer) as xs:integer >>> { >>> let $second := function($y as xs:integer) as >>> xs:integer >>> { >>> $countfun($x + $y) >>> } >>> return f:fib($n  2, $second) >>> } >>> return f:fib($n  1, $first)" /> >>> </xsl:function> >>> >>> >>> Any idea what I'm missing here, or is this perhaps an error with Saxon? >>> >>> Thanks, >>> Abel >>> >>> >>> >>> >>>  >>> Free NextGen Firewall Hardware Offer >>> Buy your Sophos nextgen firewall before the end March 2013 >>> and get the hardware for free! Learn more. >>> http://p.sf.net/sfu/sophosd2dfeb >>> >>> >>> _______________________________________________ >>> saxonhelp mailing list archived at http://saxon.markmail.org/ >>> saxonhelp@... >>> https://lists.sourceforge.net/lists/listinfo/saxonhelp >> >> >> >>  >> Free NextGen Firewall Hardware Offer >> Buy your Sophos nextgen firewall before the end March 2013 >> and get the hardware for free! Learn more. >> http://p.sf.net/sfu/sophosd2dfeb >> >> >> _______________________________________________ >> saxonhelp mailing list archived at http://saxon.markmail.org/ >> saxonhelp@... >> https://lists.sourceforge.net/lists/listinfo/saxonhelp > > > >  > Free NextGen Firewall Hardware Offer > Buy your Sophos nextgen firewall before the end March 2013 > and get the hardware for free! Learn more. > http://p.sf.net/sfu/sophosd2dfeb > > > _______________________________________________ > saxonhelp mailing list archived at http://saxon.markmail.org/ > saxonhelp@... > https://lists.sourceforge.net/lists/listinfo/saxonhelp 
Sign up for the SourceForge newsletter:
No, thanks