Created
November 3, 2019 23:41
-
-
Save chelseatroy/cf6d7d0fe21d029d8e502b1a9c6b9b8b to your computer and use it in GitHub Desktop.
Streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define ones (stream-cons 1 ones)) ;<---has not evalutated ones yet, as ones is a stream | |
(stream-ref ones 1) ;-->1 | |
(stream-ref ones 10) ;-->1 | |
(stream-ref ones 37) ;-->1 (an infinite stream of ones) | |
(define integers (stream-cons 1 (add-streams ones integers))); <--counts up from 1 | |
(define fibonacci (stream-cons 0 (stream-cons 1 (add-streams (stream-rest fibonacci) fibonacci)))) ; <--Displays fibonacci numbers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment