Skip to content

Instantly share code, notes, and snippets.

@apb2006
Created October 9, 2020 19:31
Show Gist options
  • Save apb2006/4eef5889017be4a50685a467b2754d27 to your computer and use it in GitHub Desktop.
Save apb2006/4eef5889017be4a50685a467b2754d27 to your computer and use it in GitHub Desktop.
XQuery tail recursive Fibonacci function
declare function local:fib($n as xs:integer, $a as xs:integer, $b as xs:integer){
switch ($n)
case 0 return $a
case 1 return $b
default return local:fib($n - 1, $b, $a + $b)
};
declare function local:fib($n as xs:integer){
local:fib($n,0,1)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment