Created
December 24, 2011 08:18
-
-
Save bradclawsie/1516781 to your computer and use it in GitHub Desktop.
loaddictionary.rkt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require (planet "memcached.rkt" ("jaymccarthy" "memcached.plt" 1 0))) | |
(define loaddict | |
(lambda (fn) | |
(letrec (;; our input handle | |
[in (open-input-file fn)] | |
;; our memcache conn | |
[mc (memcached "localhost" 11212)] | |
;; our function for walking the file | |
[loadlines (lambda (h) | |
(begin | |
;; get a line as l | |
(let ([l (read-line h 'any)]) | |
(if (not (eof-object? l)) | |
(begin | |
;; read the string into a bytestring, | |
;; the racket memcache client wants them | |
(let ([istr (open-input-string l)] | |
[ostr (open-output-bytes)]) | |
(begin | |
;; convert to bytestring | |
(write (read istr) ostr) | |
;; put it in memcache with value "1" | |
(memcached-set! mc | |
(get-output-bytes ostr) | |
#"1"))) | |
;; now process the next line | |
(loadlines h)) | |
#t))))]) | |
(begin | |
;; read the lines into memcache | |
(loadlines in) | |
;; close the handle | |
(close-input-port in))))) | |
(loaddict "/usr/share/dict/words") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment