Last active
June 22, 2017 08:28
-
-
Save kachayev/5789610 to your computer and use it in GitHub Desktop.
Stream implementation based on lambda / delay / force
This file contains hidden or 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
| #lang racket | |
| (define stream | |
| (letrec ((next | |
| (lambda (n) | |
| (cons n (delay (next (+ n 1))))))) | |
| (next 0))) | |
| (define head car) | |
| (define (tail st) (force (cdr st))) | |
| (head (tail (tail stream))) | |
| ;;; => 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment