Created
February 24, 2009 02:30
-
-
Save tyru/69347 to your computer and use it in GitHub Desktop.
This file contains 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 util.stream) | |
; ストリームの負数番目を取ると死ねる(GCが落ちる) | |
(define fib | |
(stream-cons 0 | |
(stream-cons 1 | |
(stream-map + fib (stream-cdr fib))))) | |
; ------------------------------------------------ | |
(define next #f) | |
(define prev #f) | |
(define runaway #f) | |
;; main | |
(define (main args) | |
(print "enter Ctrl-D(or Ctrl-Z on Windows) to escape.") | |
(newline) | |
(let/cc break | |
(let loop [(n 0) (boom #f)] | |
(when boom | |
(print (stream-ref fib n)) | |
(loop (+ n 1) #t)) | |
(display (stream-ref fib n)) | |
(flush) | |
(set! next | |
(lambda () (loop (+ n 1) #f))) | |
(set! prev | |
(lambda () (if (<= 0 (- n 1)) (loop (- n 1) #f)))) | |
(set! runaway | |
(lambda () (loop (+ n 1) #t))) | |
(break #f) | |
)) | |
; 終了したければ^Dを押す | |
(let1 c (read-byte) | |
(cond | |
[(eof-object? c)] | |
[(char-ci=? #\p (integer->char c)) (prev)] | |
[(char=? #\! (integer->char c)) (runaway)] | |
[else (next)] | |
)) | |
0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment