这是家庭作业,我不知道从哪里开始。
例如:
列表一是(1 2 3),列表二是(3 4 6)
返回29,因为(1*3)+(2*4)+(3*6)
最佳答案
不破坏答案,但这里有一点你可以期待的:
(defun sum-lists% (x y z) ...)
(defun sum-lists (x y) ... )
跟踪两个函数:
(trace sum-lists sum-lists%)
你的例子:
(sum-lists '(1 2 3) '(3 4 6))
0: (SUM-LISTS (1 2 3) (3 4 6))
1: (SUM-LISTS% (1 2 3) (3 4 6) 0)
2: (SUM-LISTS% (2 3) (4 6) 3)
3: (SUM-LISTS% (3) (6) 11)
4: (SUM-LISTS% NIL NIL 29)
4: SUM-LISTS% returned 29
3: SUM-LISTS% returned 29
2: SUM-LISTS% returned 29
1: SUM-LISTS% returned 29
0: SUM-LISTS returned 29
如果你处理角落的箱子,你也可以有:
(sum-lists '(1 2 3 4) '(3 4))
0: (SUM-LISTS (1 2 3 4) (3 4))
1: (SUM-LISTS% (1 2 3 4) (3 4) 0)
2: (SUM-LISTS% (2 3 4) (4) 3)
3: (SUM-LISTS% (3 4) NIL 11)
4: (SUM-LISTS% (4) NIL 14)
5: (SUM-LISTS% NIL NIL 18)
5: SUM-LISTS% returned 18
4: SUM-LISTS% returned 18
3: SUM-LISTS% returned 18
2: SUM-LISTS% returned 18
1: SUM-LISTS% returned 18
0: SUM-LISTS returned 18
关于list - Lisp函数接受两个列表并返回它们之间的乘积,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53772975/