Skip to content

Instantly share code, notes, and snippets.

@valvallow
Forked from cryks/gist:2653106
Created May 10, 2012 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save valvallow/2653396 to your computer and use it in GitHub Desktop.
Save valvallow/2653396 to your computer and use it in GitHub Desktop.
(use gauche.generator)
(use gauche.lazy)
(define-syntax chain
(syntax-rules ()
((_ ls proc)(proc ls))
((_ ls proc x ...)
(begin (chain ls proc)
(chain ls x ...)))))
(define (tmpgen cnt)
(generate
(lambda (yield)
(let loop ([i 0])
(when (< i cnt)
(print "Generate: " i)
(yield i)
(loop (+ i 1)))))))
(chain '(1 2 3 4 5)
(map$ (^x (* x 2)))
(map$ (^x (+ x 1))))
(take (chain (lrange 0)
(pa$ lmap (^x (* x 2))))
10)
;; => (0 2 4 6 8 10 12 14 16 18)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment