(define (subset set)
(display set)
(cond
((null? set) '() )
(else
(append (subset (cdr set))
(map (lambda (subset) (cons (car set) subset))
(subset (cdr set)))))
)
)
(define (power-set set)
(display set)
(if (null? set) '(())
(append (power-set (cdr set))
(map (lambda (power-set) (cons (car set) power-set))
(power-set (cdr set))))))
(subset '(a b c))
(power-set '(a b c))
I'm new to Scheme, and I'm trying to understand the concepts. This is an example of two scheme functions that returns the powerset when given a list. One function one using cond and the other using if. The one using cond returns '() while the one using if returns the power set. I don't understand how these two examples produce different outputs.
Any input would be great!