Scheme subset recursion problem
For the power function:
(define (p l)
(define (n next)
(if (null? next)
'()
(cons (car next)
(cons (cons (car l) (car next))
(n (cdr next))))))
(if (null? l)
'(())
(n (p (cdr l)))))
I would like to print all sets in increasing order of number of elements, and also same size in sorted order ONLY USING R5RS. For example,
If I define a list like this
(define list3 (list '1 '2 '3))
and call the funtion,
(p'(1 2 3))
My output is
(() (1) (2) (1 2) (3) (1 3) (2 3) (1 2 3))
But I want to print out like:
(() (1) (2) (3) (1 2) (1 3) (2 3) (1 2 3))
Also, for the case of
(p'(1 2 3 4))
My output is :
(()
(1)
(2)
(1 2)
(3)
(1 3)
(2 3)
(1 2 3)
(4)
(1 4)
(2 4)
(1 2 4)
(3 4)
(1 3 4)
(2 3 4)
(1 2 3 4))
But I want
(()
(1)
(2)
(3)
(4)
(1 2)
(1 3)
(1 4)
(2 3)
(2 4)
(3 4)
(1 2 3)
(1 2 4)
(1 3 4)
(2 3 4)
(1 2 3 4))
How can I make correct output?