【发布时间】:2020-03-18 00:12:42
【问题描述】:
(define (list-expand L)
(if (empty? L)
empty
(append (helper-method (car L) null)(list-expand (cdr L)))))
(define (helper-method n lst2)
(if (= n 1) '(1)
(append lst2 '(n) (helper-method (- n 1) null ))))
Testing list-expand
Expected: '(4 3 2 1 3 2 1 1), actual: '(n n n 1 n n 1 1)
Expected: '(5 4 3 2 1 2 1), actual: '(n n n n 1 n 1)
Expected: '((7 6 5 4 3 2 1 8 7 6 5 4 3 2 1), actual: '(n n n n n n 1 n n n n n n n 1)
抱歉,我不知道如何在 StackOverflow 中输入代码,希望大家不要介意。
无论如何,当我将'(n) 附加到递归返回的列表时,我知道错误出在辅助方法中。但是,由于我希望将 n 的值附加到列表中,如何解决此错误?
【问题讨论】:
-
反引号、取消引用和取消引用拼接的区别stackoverflow.com/questions/48612047/…