How could I prevent the the double recursive call to (f (car l)) without using set/setq/setf ?
(defun f(l)
(cond
((null l) nil)
((listp (car l)) (append (f (car l)) (f (cdr l)) (car (f (car l)))))
(T (list (car l)))
)
)
You think the following solves it?
(defun f(l)
(cond
((null l) nil)
((listp (car l))
(funcall #'(lambda(ff) (append ff (f (cdr l)) (list (car ff)))) (f (car l))))
(T (list (car l)))
)
)
(foo head)such that its first element is a non-empty list, because the base case of the recursion is(list head)withheada non-list. Replacing the last clause's body with(list (list head))ensures the function returns something when given a proper list as input. I recognize that this is probably not important for this exercise.