Skip to content

Instantly share code, notes, and snippets.

@apb2006
Created March 29, 2016 21:04
Show Gist options
  • Save apb2006/df4452ba69efd95c6018a1e8ed28aabf to your computer and use it in GitHub Desktop.
Save apb2006/df4452ba69efd95c6018a1e8ed28aabf to your computer and use it in GitHub Desktop.
tail recursive
(:~
: tail recursion example
:)
declare function local:sum-a($n){
if($n eq 0) then 1 else $n+ local:sum-a($n - 1)
};
declare function local:sum-b($n){
local:sum-iter(1,$n)
};
declare function local:sum-iter($sum,$n){
if($n < 2) then $sum else local:sum-iter($sum+$n,$n -1)
};
(: sum-a: max value for arg is stacksize=2983 :)
local:sum-b(30000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment