From dd1f97484adb2fab3ca95e3e1c0dbddb8e7ff4c8 Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Sat, 14 Sep 2024 11:57:30 -0400 Subject: [PATCH] continuously generate a bible --- toplevel.scm | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/toplevel.scm b/toplevel.scm index d000af8..763eaf5 100644 --- a/toplevel.scm +++ b/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")