-
-
Save aharisu/2653418 to your computer and use it in GitHub Desktop.
cutで済むならcutを使う派です
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
(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