Search code examples
lispcommon-lispclisp

EVAL/APPLY: too many arguments given to F


Hello why do i get *** - EVAL/APPLY: too many arguments given to F on function call with nested lists parameter. I cannot figure it out, since I passed a simple nested list.

(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)))
    )
)

(setq A '((1) 2 3))
(f A)

Solution

  • This better formatting should make it easy to spot the error:

    (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)))))
    

    If that does not help, use SBCL to compile the function. It will give you a very clear error message.