Skip to content

Instantly share code, notes, and snippets.

@adamretter
Created September 18, 2015 14:01
Show Gist options
  • Save adamretter/44b345106ad6cddb92fa to your computer and use it in GitHub Desktop.
Save adamretter/44b345106ad6cddb92fa to your computer and use it in GitHub Desktop.
Anonymous function recursion in XQuery
xquery version "3.0";
(:~
: Anonymous function recursion in XQuery
:
: @author Adam Retter <[email protected]>
:)
let $factorialHelper := function($f, $x) {
if($x eq 0) then
1
else
$x * $f($f, $x - 1)
}
let $factorial := function($x) {
$factorialHelper($factorialHelper, $x)
}
return
(: Calculate the factorial of 4 :)
$factorial(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment