Skip to content

Instantly share code, notes, and snippets.

@aharisu
Forked from valvallow/gist:2653396
Created May 10, 2012 14:30
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 aharisu/2653418 to your computer and use it in GitHub Desktop.
Save aharisu/2653418 to your computer and use it in GitHub Desktop.
cutで済むならcutを使う派です
(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$ (cut * <> 2))
(map$ (cut + <> 1))
(take (chain (lrange 0)
(pa$ lmap (cut * <> 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