Chapter 2, Building Abstractions with Data

Section - 2.2 - Hierarchical Data and the Closure Property

Exercise 2.32


To find power set of a set, , we can proceed as:

Power set of is:

  • if , then .
  • if , then choose any element , then:
    .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#lang sicp

(define (subsets s)
  (if (null? s)
      (list nil)
      (let (
             (rest (subsets (cdr s)))
           )
           (append
                  rest
                  (map
                      (lambda (x)
                        (cons (car s) x)
                      )  
                      rest
                  )
           )
     )
  )
)