(module dictionary mzscheme (provide file-to-dictionary in-dict?) ;; ============================================================ ;; DICTIONARY STUFF (define (empty-dictionary) (make-hash-table)) ; read-words : path -> dictionary (define (file-to-dictionary file) (define dict (make-hash-table)) (let ((ip (open-input-file file))) (let loop () (let ((l (read-line ip))) (if (eof-object? l) dict (begin (add-to-dict! dict l) (loop))))))) (define (add-to-dict! dict word) (hash-table-put! dict (string->symbol word) #t)) ; in-dict? : dict word -> boolean (define (in-dict? dict word) (hash-table-get dict (string->symbol word) (lambda () #f))))