continuously generate a bible
This commit is contained in:
parent
f9aad8ba05
commit
dd1f97484a
37
toplevel.scm
37
toplevel.scm
|
@ -1,5 +1,7 @@
|
|||
(load "markov.chicken.so")
|
||||
(import markov)
|
||||
(import markov
|
||||
(chicken format)
|
||||
srfi-18)
|
||||
|
||||
(display "Generating table (this may take a while)\n" (current-error-port))
|
||||
(define table (make-table-from-file "kjv.txt"))
|
||||
|
@ -27,7 +29,38 @@
|
|||
(define (display-a-book-of-the-bible)
|
||||
(display (join-verses (make-a-book-of-the-bible))))
|
||||
|
||||
(define (generate-continuously* previous-word time book chapter verse)
|
||||
;; For some reason, default CHICKEN only allows sleeping in increments
|
||||
;; of 1 second, but THREAD-SLEEP! in SRFI-18 allows for millisecond
|
||||
;; precision.
|
||||
(flush-output)
|
||||
(thread-sleep! time)
|
||||
(cond
|
||||
((equal? previous-word "startofbook")
|
||||
(printf "THE BOOK OF ~A~%~%~%" (generate-next-word table "of"))
|
||||
(printf "~A:1:1" (+ book 1))
|
||||
(generate-continuously* (generate-next-word table "startofverse")
|
||||
time (+ 1 book) 1 1))
|
||||
((equal? previous-word "startofchapter")
|
||||
(printf "~%~%~A:~A:1" book (+ 1 chapter))
|
||||
(generate-continuously* (generate-next-word table "startofverse")
|
||||
time book (+ 1 chapter) 1))
|
||||
((equal? previous-word "startofverse")
|
||||
(printf "~%~A:~A:~A" book chapter (+ 1 verse))
|
||||
(generate-continuously* (generate-next-word table previous-word)
|
||||
time book chapter (+ 1 verse)))
|
||||
(else (let ((first-char (string-ref previous-word 0)))
|
||||
(if (or (char-alphabetic? first-char)
|
||||
(char-numeric? first-char))
|
||||
(printf " ~A" previous-word)
|
||||
(printf "~A" previous-word))
|
||||
(generate-continuously* (generate-next-word table previous-word)
|
||||
time book chapter verse)))))
|
||||
|
||||
(define (generate-continuously time)
|
||||
(generate-continuously* "startofbook" time 0 1 1))
|
||||
|
||||
(display "Seeding from truly random source...\n")
|
||||
(seed-from-entropy)
|
||||
(display "Try (make-a-bible-verse) and (display-a-book-of-the-bible).\n")
|
||||
(display "Try (make-a-bible-verse), (display-a-book-of-the-bible), and (generate-continuously 0.1).\n")
|
||||
|
||||
|
|
Loading…
Reference in New Issue