- Code: Select all
`(defun even (n) (= (mod n 2) 0))`

(defun square (x) (* x x))

(defun c-series (n a)

(if (= n 0)

a

(if (even n)

(log (c-series (- n 1) a))

(square (c-series (- n 1) a))

)

)

)

What if I wanted to print out a finite list of all the intermediate c-series values?

A list containing

- Code: Select all
`(let (a 5)`

((c-series (1 a)) (c-series (2 a)) (c-series (3 a)) ...

)

Of course, with actual reuse of the previous results.

I just can't seem to find a way to fit the recursion in there. (I've played with Haskell before and just can't get my head around how to implement this type of recursion in Lisp). Do I really need a helper function? Thanks for helping me on my way,