我有一个用普通LISP编写的函数,它将2个多项式的第一项乘以我想要的函数(使用我编写的其他函数):
(defun firsttermmultiply (p1 p2)
(let ((t1p1(car p1))
(t1p2(car p2))
(rem1(cdr p1))
(rem2(cdr p2)))
(cons (coeff t1p1 t1p2) (cutfront t1p1 t1p2))
)
)
p1和p2是多项式,我想通过这两个列表进行递归,这样我就有一个长列表,其中p1和p2中的所有项都已应用于该行:
(cons (coeff t1p1 t1p2) (cutfront t1p1 t1p2))
我知道它需要使用rem1和rem2作为单独递归行的参数,但我无法理解结构。
我必须在功能上这样做,所以我不能使用循环结构,只能递归。
答案 0 :(得分:1)
是其中之一吗?假设这些多边形具有相同的顺序。
(defun firsttermmultiply (p1 p2)
(if (or (null p1) (null p2))
nil
(let ((t1p1(car p1))
(t1p2(car p2))
(rem1(cdr p1))
(rem2(cdr p2)))
(cons (coeff t1p1 t1p2) (firsttermmultiply rem1 rem2)))))
(defun firsttermmultiply (p1 p2)
(if (or (null p1) (null p2))
nil
(let ((t1p1(car p1))
(t1p2(car p2))
(rem1(cdr p1))
(rem2(cdr p2)))
(cons (cons (coeff t1p1 t1p2) (cutfront t1p1 t1p2))
(firsttermmultiply rem1 rem2)))))
(defun firsttermmultiply (p1 p2)
(if (or (null p1) (null p2))
nil
(let ((t1p1(car p1))
(t1p2(car p2))
(rem1(cdr p1))
(rem2(cdr p2)))
(cons (coeff t1p1 t1p2)
(cons (cutfront t1p1 t1p2)
(firsttermmultiply rem1 rem2))))))