I was reading the book On Lisp by Paul Graham. In Chapter 4, Utility Functions, he gives examples of small functions that operate on lists, which would be helpful while writing
push
changes the symbol binding in scope. Thus the recursion (rflatten el acc)
has it's own acc
which is the result there but you don't do anything with the returned result and it doesn't alter the callee acc
.
Perhaps a (setf acc (rflatten el acc))
would fix that:
(defun flatten (lst)
(labels ((rflatten (lst1 acc)
(dolist (el lst1)
(if (listp el)
(setf acc (rflatten el acc))
(push el acc)))
acc))
(reverse (rflatten lst nil))))