Created
October 2, 2013 07:21
-
-
Save xquery/6790119 to your computer and use it in GitHub Desktop.
fully generalized recursion with Y-combinator in xquery 3.0 ... recursion via 'deferred execution'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
let $makeFactorialFunc := function($givenFactFunc) { | |
let $fact := function($n) { | |
if( $n lt 2 ) | |
then 1 | |
else $n * $givenFactFunc($n - 1) | |
} | |
return $fact | |
} | |
let $y := function($le) { | |
function($f) { | |
$f($f) | |
}( function($f) { | |
$le( | |
function($x) { ($f($f))($x) } | |
) | |
}) | |
} | |
let $factorial := $y($makeFactorialFunc) | |
return $factorial(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment