Silas Vedder
2 years ago
3 changed files with 53 additions and 3 deletions
@ -0,0 +1,48 @@ |
|||||||
|
(define-module (bible-tools) |
||||||
|
#:use-module (srfi srfi-1) |
||||||
|
#:use-module (srfi srfi-98) |
||||||
|
#:use-module (rnrs io ports) |
||||||
|
#:use-module (rnrs bytevectors) |
||||||
|
#:export (mapcan |
||||||
|
get-bible |
||||||
|
string->bible |
||||||
|
book |
||||||
|
chapter |
||||||
|
verse |
||||||
|
text |
||||||
|
get-book |
||||||
|
get-chapter |
||||||
|
get-verse |
||||||
|
with-bible)) |
||||||
|
|
||||||
|
(define (mapcan f l) (apply append (map f l))) |
||||||
|
(define (make-bible-path name) |
||||||
|
(string-append (get-environment-variable "HOME") "/.bible/" name ".tsv")) |
||||||
|
(define (get-bible name) |
||||||
|
(call-with-input-file (make-bible-path name) (compose utf8->string get-bytevector-all))) |
||||||
|
|
||||||
|
(define (string->verse string) |
||||||
|
(string-split string #\tab)) |
||||||
|
|
||||||
|
(define (string->bible string) |
||||||
|
(map string->verse |
||||||
|
(filter (lambda (str) (not (string=? str ""))) |
||||||
|
(string-split string #\newline)))) |
||||||
|
|
||||||
|
(define book car) |
||||||
|
(define chapter cadddr) |
||||||
|
(define verse (compose cadddr cdr)) |
||||||
|
(define text (compose cadddr cddr)) |
||||||
|
|
||||||
|
(define (get-num bible query part) |
||||||
|
(filter (lambda (v) (= query (string->number (part v)))) bible)) |
||||||
|
(define (get-book book-name bible) |
||||||
|
(filter (lambda (v) (string=? book-name (book v))) bible)) |
||||||
|
(define (get-chapter chapter-number book) |
||||||
|
(get-num book chapter-number chapter)) |
||||||
|
(define (get-verse verse-number chapter) |
||||||
|
(get-num chapter verse-number verse)) |
||||||
|
|
||||||
|
(define (with-bible b f) |
||||||
|
(when (procedure? f) |
||||||
|
(f (string->bible (get-bible b))))) |
Loading…
Reference in new issue