Created
October 28, 2013 00:06
-
-
Save netoneko/7189443 to your computer and use it in GitHub Desktop.
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
(require 'clojure.string) | |
(def records {}) | |
(def commands {}) | |
(def commands | |
(assoc commands "add" | |
(fn [k v] (def records (assoc records k v))))) | |
(def commands | |
(assoc commands "delete" | |
(fn [person] (def records (dissoc records person))))) | |
(def commands | |
(assoc commands "print" | |
(fn [] (println records)))) | |
(while true | |
(print "> ") | |
(flush) | |
(def line (clojure.string/trim (read-line))) | |
(def tokens (clojure.string/split line #"\s")) | |
(if (contains? commands (first tokens)) ( | |
(defn command [& args] (get commands (first tokens))) | |
(println command) | |
(def args (rest tokens)) | |
(println args) | |
(apply command args) | |
(flush)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it should be (apply (command) args)