-
Notifications
You must be signed in to change notification settings - Fork 12
/
quotes.rkt
35 lines (28 loc) · 955 Bytes
/
quotes.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#lang racket
(require racket/runtime-path)
(define *the-channel* (make-channel))
(define-runtime-path quotes-file "quotes")
(define *dealer*
(thread
(lambda ()
(let re-read ()
;; Instead of, or in addition to, reading the quotes file
;; .. how about
;; SELECT * FROM log
;; JOIN log_word_map ON log_word_map.log_id = log.rowid
;; WHERE log_word_map.word = 'lets'
;; AND (log.text GLOB '[lL]et?s*' OR log.text GLOB '[lL]ets*')
(fprintf (current-error-port)
"Reading quotes file~%")
(let push-one ([all (shuffle (call-with-input-file quotes-file read))])
(if (null? all)
(re-read)
(begin
(channel-put *the-channel* (car all))
(push-one (cdr all)))))))))
(provide one-quote)
(define (one-quote)
(channel-get *the-channel*))
(module+ main
(display (one-quote))
(newline))