(use '[clojure.string :only (split split-lines)]) ; file is tab-seperated pairs of foreign and native words (let [contents (slurp "100a.txt" :encoding "utf-8") lines (split-lines contents) pairs (map #(split % #"\t") lines)] (loop [my-pairs (shuffle pairs)] (let [pair (first my-pairs)] (do (println) (println (first (first my-pairs))) (if (not= (read-line) (second pair)) (do (println "wrong, correct is:" (second pair)) (recur (shuffle my-pairs))) (do (println "correct") (if (seq (rest my-pairs)) ; (seq idiomatic for (not (empty? (recur (rest my-pairs)))))))))
Tuesday, January 03, 2012
Vocabulary trainer in Clojure
Labels:
clojure
Subscribe to:
Post Comments (Atom)
0 Kommentare:
Post a Comment