# lab11 - is 1 and whose cdr is a promise. The only thing you...

This preview shows page 1. Sign up to view the full content.

Week 11 solutions LAB === 1. The result of (delay . ..) is of type *promise*. The result of (force (delay . ..)) is of whatever type the ". .." would be without delay; in this case it's (force (delay (+ 1 27))) and that's of type integer. 2. (stream-cdr (stream-cdr (cons-stream 1 '(2 3)))) causes an error because (2 3) isn't a stream. (stream-cdr (cons-stream 1 '(2 3))) --> (2 3) (stream-cdr '(2 3)) --> (force (cdr '(2 3))) --> (force '(3)) but (3) isn't a promise! 3. (delay (enumerate-interval 1 3)) returns a promise. (stream-enumerate-interval 1 3) returns a stream, i.e., a pair whose car
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: is 1 and whose cdr is a promise. The only thing you can do with the result of (delay . ..) is FORCE it; you can't ask for its stream-car or stream-cdr, etc. By contrast, with the stream, you can stream-car or stream-cdr it, but *not* force it, because it's not a promise. 4. the 4-2-1 stream. (define (next-num n) (if (even? n) (/ n 2) (+ (* n 3) 1))) (define (num-seq n) (cons-stream n (num-seq (next-num n)))) (define (seq-length s) (if (= (stream-car s) 1) 1 (+ 1 (seq-length (stream-cdr s)))))...
View Full Document

## This note was uploaded on 05/12/2010 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Ask a homework question - tutors are online