3 ms·
I 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)
by tc 18y ago
I 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.