Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Created November 3, 2019 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelseatroy/cf6d7d0fe21d029d8e502b1a9c6b9b8b to your computer and use it in GitHub Desktop.
Save chelseatroy/cf6d7d0fe21d029d8e502b1a9c6b9b8b to your computer and use it in GitHub Desktop.
Streams
(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