Skip to content

Commit

Permalink
Add an example of another form of optimizable tail recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Apr 16, 2019
1 parent 6db9775 commit 1afbe03
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions example/count.tr
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
function counthelper(n, v) =
if v then call counthelper(n + 1, largest ((count v) - 1) v)
function counthelperA(n, v) =
if v then call counthelperA(n + 1, largest ((count v) - 1) v)
else n

function mycount(v) = call counthelper(0, v)
function counthelperB(n, v) =
if !v then n
else call counthelperB(n + 1, largest ((count v) - 1) v)

call mycount(10000d2)
function mycountA(v) = call counthelperA(0, v)
function mycountB(v) = call counthelperB(0, v)

call mycountB(10000d2)

0 comments on commit 1afbe03

Please sign in to comment.