PageRenderTime 32ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 4ms app.codeStats 0ms

/quotes.rkt

http://github.com/elibarzilay/rudybot
Shell | 32 lines | 23 code | 6 blank | 3 comment | 0 complexity | 95c2793ad859713ad86a0addf94e38de MD5 | raw file
 1#! /bin/sh
 2#| Hey Emacs, this is -*-scheme-*- code!
 3exec  racket -l errortrace --require $0 --main -- ${1+"$@"}
 4|#
 5
 6#lang racket
 7
 8(require (planet offby1/offby1:2:1/shuffle))
 9
10(define *the-channel* (make-channel))
11
12(define *dealer*
13  (thread
14   (lambda ()
15     (let re-read ()
16       (fprintf (current-error-port)
17                "Reading quotes file~%")
18       (let push-one ([all (shuffle (call-with-input-file "quotes" read))])
19         (if (null? all)
20             (re-read)
21             (begin
22               (channel-put *the-channel* (car all))
23               (push-one (cdr all)))))))))
24
25(provide one-quote)
26(define (one-quote)
27  (channel-get *the-channel*))
28
29(provide main)
30(define (main . args)
31  (display (one-quote))
32  (newline))