Consider the following function definition in Lisp:
(defun f (l)
(cond
((null l) 0)
((> (f (car l)) 2) (+ (car l) (f (cdr l))))
(T (f (car l)))
)
)
Give a solution to avoid the double recursive call (f (car l))
. You will not use set,setq,setf. Justify the answer.
This is how I proceeded:
(defun f2 (l)
(cond
((null l) 0)
((lambda (x)
(cond
((> x 2) (+ (car l) (f2 (cdr l))))
(T x)
)
) (f2 (car l))
)
)
)
I want to hear some opinions. By the way, it's just an exercise. This function is not suposed to do something coherent.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…