#lang racket (define empty-stream '()) (define-syntax stream-cons (syntax-rules () ((_ term rest) (cons term (λ () rest))))) (define stream-first car) (define stream-rest (λ (s) ((cdr s)))) (define stream-empty? null?) (define (stream-zip-with f . argstreams) (if (stream-empty? (car argstreams)) empty-stream (stream-cons (apply f (map stream-first argstreams)) (apply stream-zip-with f (map stream-rest argstreams))))) (define (stream-take s n) (cond ((zero? n) '()) ((stream-empty? s) '()) (else (cons (stream-first s) (stream-take (stream-rest s) (- n 1)))))) (define fibonacci- (stream-cons 0 (stream-cons 1 (stream-zip-with + fibonacci- (stream-rest fibonacci-))))) ;fibonacci- (time (drop (stream-take fibonacci- 31) 30))