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

Sorry, I don't know how to enter code in StackOverflow I hope yall don't mind.

Anyways, I know the error is in the helper method when I append '(n) to the list returned by recursion. However, how can I fix this error since I want the value of n to be appended to the list?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Difference between backquote, unquote and unquote-splicing https://stackoverflow.com/questions/48612047/backquote-unquote-and-unquote-splicing-in-normal-functions/48612956#48612956 – Eggcellentos Mar 18 '20 at 14:17

1 Answers1

1

Don't quote it, call the list function to create a list with variable arguments.

(define (helper-method n lst2)
  (if (= n 1) '(1)
      (append lst2 (list n) (helper-method (- n 1) null ))))
Barmar
  • 741,623
  • 53
  • 500
  • 612