You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

2 years ago
(define-module (bible-tools)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
2 years ago
#:use-module (srfi srfi-98)
#:use-module (rnrs io ports)
#:use-module (rnrs bytevectors)
#:export (mapcan
get-bible
string->bible
clean-strings
2 years ago
book
chapter
verse
text
get-book
get-chapter
get-verse
let-bible
call-with-book
call-with-chapter
with-bible
with-book
with-chapter))
2 years ago
(define (mapcan f l) (apply append (map f l)))
(define make-bible-path
(cut string-append (get-environment-variable "HOME")
"/.bible/" <> ".tsv"))
2 years ago
(define (get-bible name)
(call-with-input-file (make-bible-path name)
(compose utf8->string get-bytevector-all)))
2 years ago
(define string->verse (cut string-split <> #\tab))
(define clean-strings
(cut filter (compose not (cut string=? <> "")) <>))
2 years ago
(define string->bible
(compose (cut map string->verse <>)
clean-strings
(cut string-split <> #\newline)))
2 years ago
(define book first)
(define chapter fourth)
(define verse fifth)
(define text sixth)
2 years ago
(define (get-num query bible part)
(filter (compose (cut = query <>) string->number part) bible))
2 years ago
(define (get-book book-name bible)
(filter (compose (cut string=? book-name <>) book) bible))
(define get-chapter (cut get-num <> <> chapter))
(define get-verse (cut get-num <> <> verse))
2 years ago
(define (with-bible b f)
(when (procedure? f) (f (string->bible (get-bible b)))))
(define (call-with-book book thunk)
(compose thunk (cut get-book book <>)))
(define (call-with-chapter book chapter thunk)
(lambda (bible) (thunk (get-chapter (string->number chapter)
(get-book book bible)))))