lab13 - The only thing you can do with the result of(delay...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Week 13 solutions LAB Err:510 1. The result of (delay . ..) is of type *promise*. The result of (force (delay . ..)) is of whatever type the ". .." would be without delay 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 is 1 and whose cdr is a promise.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The only thing you can do with the result of (delay . ..) is FORCE it 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))))) Sheet1 Page 2 in this case it's (force (delay (+ 1 27))) and that's of you...
View Full Document

This note was uploaded on 09/14/2009 for the course PEIS 100 taught by Professor Mckenzie during the Spring '08 term at Berkeley.

Page1 / 2

lab13 - The only thing you can do with the result of(delay...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online