Consider the following function definition in Lisp:
(defun Fct(F L) (cond ((null L) nil) ((funcall F (car L)) (cons (funcall F (car L)) (Fct F (cdr L)) ) ) (T nil) ) )
Give a solution to avoid the double call
(funcall F (car L))
.You wil not use set,setq,setf. Justify the answer.
This is how I redefined the function:
(defun Fct2(F L)
(funcall #'(lambda (x)
(cond
((null L) nil)
(x (cons x (Fct2 F (cdr L)) ) )
(T nil)
)
)
(F (car L))
)
)
I works, but I can't see if there is no more double call behind. Also I have seen someone who did it in another way:
(defun redefine(f l)
(funcall #' (lambda (x)
(cond
((null l) nil)
(x (cons x (Fct f (cdr l))))
(t nil)
)
)
(funcall f (car l))
)
)
(using the old Fct inside)
But I think that Fct2 is the good way to proceed. I'd like to hear some opinions.