Implementing powerset in scheme
问题 I am trying to implement a powerset function in Scheme in two ways. One way is using tail recursion, and I did it like this: (define (powerset list) (if (null? list) '(()) ;; if list is empty, its powerset is a list containing the empty list (let ((rest (powerset (cdr list)))) ;; define "rest" as the result of the recursion over the rest of list (append (map (lambda (x) (cons (car list) x)) rest) ;; add the first element of list to the every element of rest (which is a sublist of rest) rest))