Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created December 24, 2011 08:18
Show Gist options
  • Save bradclawsie/1516781 to your computer and use it in GitHub Desktop.
Save bradclawsie/1516781 to your computer and use it in GitHub Desktop.
loaddictionary.rkt
#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