From 1afbe0333348b46540de18783834272cc6c62c55 Mon Sep 17 00:00:00 2001 From: Juuso Mikkonen Date: Tue, 16 Apr 2019 17:05:39 +0300 Subject: [PATCH] Add an example of another form of optimizable tail recursion --- example/count.tr | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/example/count.tr b/example/count.tr index c29a20d..5521e4e 100644 --- a/example/count.tr +++ b/example/count.tr @@ -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)