next up previous
Next: 3. Programming Assignment Up: No Title Previous: 1. Background

2. Tutorial Exercises

You should prepare these exercises for oral presentation in tutorial.

Tutorial exercise 1:

The following procedure all-choices (which you will use in doing this problem set) takes as argument a list of n lists tex2html_wrap_inline459 and returns a list whose elements are all possible lists of the form tex2html_wrap_inline461, where tex2html_wrap_inline463 is chosen from tex2html_wrap_inline465, tex2html_wrap_inline467 is chosen from tex2html_wrap_inline469, ..., tex2html_wrap_inline471 is chosen from tex2html_wrap_inline473. (Mathematicians call this operation the Cartesian product of the input lists.) For example, (all-choices '((1 2) (a b c))) should return

((1 a) (1 b) (1 c) (2 a) (2 b) (2 c))

(define (all-choices possibilities-list)
  (if (null? possibilities-list)
      '(())
      (let ((rest (all-choices (cdr possibilities-list))))
        (flatten
         (map
          (lambda (choice-for-first)
            (map (lambda (follow-on)
                   (cons choice-for-first follow-on))
                 rest))
          (car possibilities-list))))))

Explain how this procedure works. In general, how many possible choices will there be as a function of the input list? How could you modify the procedure to produce a stream of choices rather than a list of choices. (Assume that the argument is still a list.)
Check the 6.001 discussion forum for tutorial-ex-01
Look here for information about the forum.

Tutorial exercise 2:

Using cons-stream, stream-map, stream-filter, create expressions that define an infinitely long stream of 1's and an infinitely long stream of the positive integers. Be prepared to explain why your expressions work.
Check the 6.001 discussion forum for tutorial-ex-02
Look here for information about the forum.

Tutorial exercise 3:

Using the same tools, create an expression that defines an infinitely long stream of the powers of 2 (i.e. 1, 2, 4, 8, 16, ...).
Check the 6.001 discussion forum for tutorial-ex-03
Look here for information about the forum.

Tutorial exercise 4:

Do exercise 3.54 from the text.
Check the 6.001 discussion forum for tutorial-ex-04
Look here for information about the forum.

Tutorial exercise 5:

Do exercise 3.55 from the text.
Check the 6.001 discussion forum for tutorial-ex-05
Look here for information about the forum.


next up previous
Next: 3. Programming Assignment Up: No Title Previous: 1. Background

Hal Abelson
Fri Mar 27 14:32:25 EST 1998