Created
October 9, 2020 19:31
-
-
Save apb2006/4eef5889017be4a50685a467b2754d27 to your computer and use it in GitHub Desktop.
XQuery tail recursive Fibonacci function
This file contains hidden or 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
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