Can someone show my the error in this code please? I haven't been familiar with recursion so that I don't really understand whats wrong with the code below.
(define (counting lst)
(if (null? lst)
'()
(string-append (number->string (car (car lst)))
", "
(number->string (length (cdr (car lst))))
(counting (cdr lst)))))
Input: '((2 b a) (1 f e c) (0 m))
output expected from the code: "2, 2\n1, 3\n0, 1\n"
Actual output from the code above:
string-append: contract violation
expected: string?
given: '()
argument position: 4th
other arguments...:
"0"
", "
"1"
As I understand,
Base case: if length of the list nested = 0, or null, it is '()
Inductive case: append the first number in the list nested with "," and the length of the rest of the list nested.
Is my idea correct? If not, where I'm wrong ?? Thank in advance!
string-appendwith an empty list as an argument? The error message that got, when copied into your question, will help future users with the same problem find the solution.