I have a problem with deep recursion in scheme
The output should be
(1 2 3 (4 5))
~> ((1) (2) (3) ((4) (5)))
But my output is (1 (2 (3 ((4 (5 ())) ())))).
It seems like the quote is at the wrong place
I got these
(define (DoublebubbleLst lst)
(cond ((null? lst) lst)
((not (pair? lst))
(append lst))
(else(list
(DoublebubbleLst (car lst))
(DoublebubbleLst (cdr lst))))))
And what’s my problem
>Solution :
This seems to work:
(define (double-bubble-list lst)
(cond ((null? lst) lst)
((not (list? (car lst)))
(cons (list (car lst))
(double-bubble-list (cdr lst))))
(else (cons (double-bubble-list (car lst))
(double-bubble-list (cdr lst))))))
Example:
> (double-bubble-list '(1 2 3 (4 5)))
'((1) (2) (3) ((4) (5)))