Search code examples
schemelispsicpmit-scheme

What is the equivalent of the rest procedure in SICP in MIT Scheme 9.2?


I am on exercise 2.32 which presents the following code:

(define (subsets s)
  (if (null? s)
      (list nil)
      (let ((rest (subsets (cdr s))))
        (append rest (map <??> rest)))))

When I try to call the rest procedure in MIT Scheme 9.2 it doesn't recognize the procedure (there is a similar issue with nil in the book, which is replaced by () in modern Scheme). What is the equivalent rest procedure in modern Scheme? I don't believe it is cdr because cdr is used throughout the book.


Solution

  • You're misunderstanding the exercise - rest is not a procedure, is a local variable that corresponds the the rest of the subsets (perhaps you should take a look at the documentation regarding let). This is what the book is asking:

    (define (subsets set)
      (if (null? set)
          (list '())
          (let ((rest (subsets (cdr set))))
            (append rest
                    (map (lambda (sets) (cons (car set) sets))
                         rest)))))