Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created December 10, 2012 00:21
Show Gist options
  • Save dyoo/4247639 to your computer and use it in GitHub Desktop.
Save dyoo/4247639 to your computer and use it in GitHub Desktop.
an implementation of iterate
#lang racket
;; inspired by http://zvon.org/other/haskell/Outputprelude/iterate_f.html
(define (iterate f acc)
(make-do-sequence
(lambda ()
(values
(lambda (x) x)
(lambda (x) (f x))
acc
#f
#f
#f))))
(define doubles (iterate (lambda (x) (* 2 x)) 1))
(for/list ([x doubles]
[n (in-range 10)])
x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment