/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!
  3. exec racket -l errortrace --require $0 --main -- ${1+"$@"}
  4. |#
  5. #lang racket
  6. (require (planet offby1/offby1:2:1/shuffle))
  7. (define *the-channel* (make-channel))
  8. (define *dealer*
  9. (thread
  10. (lambda ()
  11. (let re-read ()
  12. (fprintf (current-error-port)
  13. "Reading quotes file~%")
  14. (let push-one ([all (shuffle (call-with-input-file "quotes" read))])
  15. (if (null? all)
  16. (re-read)
  17. (begin
  18. (channel-put *the-channel* (car all))
  19. (push-one (cdr all)))))))))
  20. (provide one-quote)
  21. (define (one-quote)
  22. (channel-get *the-channel*))
  23. (provide main)
  24. (define (main . args)
  25. (display (one-quote))
  26. (newline))