4 ms·
There's recursion and then there's tail recursion. Recursion is idiomatic of all functional languages. Using the loop macro as in your example is iterative and
by jgrant27 18y ago
There's recursion and then there's tail recursion. Recursion is idiomatic of all functional languages. Using the loop macro as in your example is iterative and hence some of the contention about whether that is idiomatic for a functional language such as CL. Some would say that this is a a purist argument but some things are actually easier to write recursively.
- tc 18y agoI like the tail recursion, but it really would be more idiomatic in CL to write: (defun integrate (f a b &aux (dx *small-dx*)) (labels ((rec (x sum) (if (> x b) sum (rec (+ x dx) (+ sum (* (funcall f x) dx)))))) (rec a 0)))
- jgrant27 18y agoAbsolutely not. Nested functions are LEXICALLY scoped in CL. Why the aversion ?
- jrockway 18y agoThere is nothing wrong with your code, it's just that nobody else does it that way. Personally, I find code easier to read when it looks something like what I expect... but OTOH, it's very obvious what your code does too.