42 lines
1.2 KiB
Scheme
42 lines
1.2 KiB
Scheme
(import (chicken condition)
|
|
(chicken io)
|
|
(chicken process-context)
|
|
(chicken random)
|
|
(chicken format)
|
|
http-client
|
|
utf8)
|
|
|
|
(define *api-url* (get-environment-variable "MASTODON_API_URL"))
|
|
(define *access-token* (get-environment-variable "MASTODON_ACCESS_TOKEN"))
|
|
(define file "./words.txt")
|
|
|
|
(define (file-num-lines file-path)
|
|
(let ((file (open-input-file file-path)))
|
|
(let loop ((num-lines 0))
|
|
(if (eof-object? (read-line file))
|
|
(begin (close-input-port file)
|
|
num-lines)
|
|
(loop (+ 1 num-lines))))))
|
|
|
|
(define (file-line-at file-path n)
|
|
(let ((file (open-input-file file-path)))
|
|
(let loop ((m 0)
|
|
(cur (read-line file)))
|
|
(cond
|
|
((= m n)
|
|
(begin
|
|
(close-input-port file)
|
|
cur))
|
|
|
|
((eof-object? cur)
|
|
(begin
|
|
(close-input-port file)
|
|
(signal (format "~s is greater than the number of lines in ~s" n file-path))))
|
|
|
|
(else (loop (+ 1 m) (read-line file)))))))
|
|
|
|
(let* ((n (pseudo-random-integer (file-num-lines file)))
|
|
(line (file-line-at file n)))
|
|
(display "Seize the means of ")
|
|
(display line)
|
|
(display "!\n"))
|