Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active June 22, 2017 08:28
Show Gist options
  • Select an option

  • Save kachayev/5789610 to your computer and use it in GitHub Desktop.

Select an option

Save kachayev/5789610 to your computer and use it in GitHub Desktop.
Stream implementation based on lambda / delay / force
#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