Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Recursion Lisp递归返回NIL_Recursion_Lisp - Fatal编程技术网

Recursion Lisp递归返回NIL

Recursion Lisp递归返回NIL,recursion,lisp,Recursion,Lisp,比如说,我在别处有一个预定义的函数“sum” 在我完成(setq a'(4 3 4))和(setq b'(6 10 9)) 我做了(递归a b) 但是,我不断得到'nil'作为返回值。这个递归有什么不对 Trace目前没有任何帮助 (defun recurse (x y) (cond ( (null x) nil) ) (t (sum (car x) (car y) ) (recurse (cdr x) (cdr y)) ) ) ) 你

比如说,我在别处有一个预定义的函数“sum”

在我完成
(setq a'(4 3 4))
(setq b'(6 10 9))

我做了
(递归a b)

但是,我不断得到'nil'作为返回值。这个递归有什么不对

Trace目前没有任何帮助

(defun recurse (x y)
    (cond
         ( (null x) nil) )
         (t   (sum (car x) (car y) ) (recurse (cdr x) (cdr y)) )

    )
)

你需要把结果加起来;否则,它们就会被扔掉

(defun recurse (x y)
  (cond
    ((null x) nil)
    (t (cons (sum (car x) (car y))
             (recurse (cdr x) (cdr y))))))

您正在添加数字并丢弃结果。