;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname streams) (read-case-sensitive #t) (teachpacks ((lib "docs.rkt" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "docs.rkt" "teachpack" "htdp")) #f))) (define (stream f x) (cons (f x) (list f))) (stream (lambda(x)(* 2 x)) 5) ; stream w first element 10 (define (square x) (* x x)) ;(square 2) ; returns 4 (stream square 2) ; returns stream w first element 4 (define ss (stream square 2)) (define (head str) (car str)) (head ss) ; unbounded list of squares of values starting with 4 = 2 squared (head (stream (lambda(x)(* 2 x)) 5)) (define (tail str) (cons (apply (car (cdr str)) (list (car str))) (cdr str))) (tail ss) (head (tail ss)) (head (tail (tail ss))) (tail (tail ss))