Created
October 31, 2011 12:59
-
-
Save valvallow/1327442 to your computer and use it in GitHub Desktop.
mortal
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
#!/usr/local/bin/gosh | |
(use srfi-1) ; list-index | |
(use srfi-14) ; char-set | |
(use math.mt-random) | |
(use gauche.parseopt) | |
(define (usage) | |
(print "Usage: mortal [options ...]") | |
(print " - s|sleep : milli second sleep") | |
(print " - l|length") | |
(print " - h|help") | |
(exit 0)) | |
(define (make-lookupper keys values :optional (comp eq?)) | |
(^ (key) | |
(let1 idx (list-index (pa$ comp key) keys) | |
(and idx (list-ref values idx))))) | |
(define rand | |
(let1 m (make <mersenne-twister> :seed (sys-time)) | |
(^ (:optional (len 2)) | |
(mt-random-integer m len)))) | |
(define (main args) | |
(let-args (cdr args) | |
((n "s|sleep=i" 1000) | |
(len "l|length=i") | |
(help "h|help" => usage)) | |
(let* ((src1 (char-set->list #[a-zA-Z0-9])) | |
(src2 (char-set->list #[a-zA-Z0-9])) | |
(lookup (make-lookupper src1 src2))) | |
(let1 body (^ _ (sys-nanosleep (* n 100000)) | |
(let1 char (list-ref src1 (rand (length src1))) | |
(display (if (zero? (rand 2)) | |
char | |
(lookup char))) | |
(flush))) | |
(if len | |
(for-each body (iota len)) | |
(while #t (body))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment