On Sun, Feb 9, 2025 at 2:36 AM Alexander Burger <picolisp@software-lab.de> wrote:
> > You can also have use cases for both at the same time. > > For example, a tree can be iterated by recursing on the left branches > and then looping on the right branches: > > Noted. A good thing to remember. It is interesting that I don't see much performance difference between tco and recur in most cases. Perhaps the primary difference is their resource usage? For example, using (mike)'s fibo example.... and simply replacing tco with recur (see code at end) I initially expected (fiboRecur) to have a similar bench profile to (fibo). : (bench (fibo 37)) 2.779 sec -> 24157817 : (bench (fiboRecur 37)) 0.000 sec -> 24157817 : (bench (fiboTco 37)) 0.000 sec -> 24157817 /Lindsay # The functions used above (de fibo (N) (if (>= 2 N) 1 (+ (fibo (dec N)) (fibo (- N 2))) ) ) (de fiboTco (N) (let (A 0 B 1) (tco (N A B) (if (=0 N) A (tc (dec N) B (+ A B)) ) ) ) ) (de fiboRecur (N) (let (A 0 B 1) (recur (N A B) (if (=0 N) A (recurse (dec N) B (+ A B)) ) ) ) )