Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2a9dba2f9e
Fetching contributors…

Cannot retrieve contributors at this time

32 lines (24 sloc) 0.841 kb
#lang racket
;; Example 3.54
(require racket/stream)
(define (my-stream-map proc . argstreams)
(if (stream-empty? (car argstreams))
empty-stream
(stream-cons
(apply proc (map stream-first argstreams))
(apply my-stream-map
(cons proc (map stream-rest argstreams))))))
(define (mul-streams s1 s2)
(my-stream-map * s1 s2))
(define (integers-starting-from n)
(stream-cons n (integers-starting-from (+ n 1))))
(define integers (integers-starting-from 1))
(define factorials (stream-cons 1
(mul-streams factorials
(integers-starting-from 2)))) ;; n! = (n-1)!*n
(stream-ref factorials 0)
(stream-ref factorials 1)
(stream-ref factorials 2)
(stream-ref factorials 3)
(stream-ref factorials 4)
(stream-ref factorials 5)
Jump to Line
Something went wrong with that request. Please try again.