From: Frank <fa...@ri...> - 2016-01-25 05:14:01
|
I believe it could be done this way: (defun pow2 (n &optional (acc 1)) (cond ((> n 0) (pow2 (- n 1) (* acc 2))) (t acc))) On Mon, 2016-01-25 at 05:26 +0100, Mei...@gm... wrote: > Hi, > > > WARNING! NEWBIE QUESTION AHEAD! WARNING! :) > > Recently I read about proper tail recursion and its > benefits for recursion depth. > > My questions are: > Does SBCL supports proper tail recursion ? > And if yes: > I wrote a simple recursive function, which calculates > powers of 2: > > ( defun pow2 > (n) > > > ( cond (( > n 0 ) ( * 2 ( pow2 ( - n 1 )))) > (t 1 ))) > > > At least it calculates the corrects results. ;) > Is it possible to recode this function in way, which > makes it proper tail recursive? > > Thank you very much for any help in advance! > Best regards, > Meino > > > > > > ------------------------------------------------------------------- > ----------- > Site24x7 APM Insight: Get Deep Visibility into Application > Performance > APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month > Monitor end-to-end web transactions and take corrective actions now > Troubleshoot faster and improve end-user experience. Signup Now! > http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 > _______________________________________________ > Sbcl-help mailing list > Sbc...@li... > https://lists.sourceforge.net/lists/listinfo/sbcl-help |