Last active
August 29, 2015 14:25
-
-
Save shirok/acf7c10f4b617a323a27 to your computer and use it in GitHub Desktop.
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
;; -*- coding:utf-8 -*- | |
(use util.match) | |
(use data.random) | |
(set! (random-data-seed) (sys-time)) | |
(define *parts* (map (^s (cons s (string-length s))) '("進捗" "どう" "です" "か"))) | |
(define index-gen (integers$ (length *parts*))) | |
(define *stream* (generator->lseq (^[] (~ *parts* (index-gen))))) | |
(let loop ([s *stream*] [cnt 0]) | |
(match s | |
[() (print "???") (print cnt "文字で煽られました。")] | |
[(("進捗" . _) ("どう" . _) ("です" . _) ("か" . _) x . _) (loop (take s 4) cnt)] | |
[((x . a) . r) (display x) (loop r (+ cnt a))])) |
一定のコレクションからランダムに選んでくるジェネレータがあるのも便利だなと思ったので足した。HEADを使うと*stream*
はこう書ける。
(define *stream*
(generator->lseq
(samples$ (map (^s (cons s (string-length s))) '("進捗" "どう" "です" "か")))))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ちょっと直した。終端文字列にマッチ成功の時にストリームをぶった切れば、特別扱いする必要が減る。