Skip to content

Instantly share code, notes, and snippets.

@drcode
Last active December 14, 2015 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drcode/5040624 to your computer and use it in GitHub Desktop.
Save drcode/5040624 to your computer and use it in GitHub Desktop.
(ns groupon.core
(require [clojure.string :refer [lower-case]]))
;;functional
(defn add-item [items item]
(conj items item))
(defn edit-item [items index item]
(assoc items index item))
(defn delete-item [items n]
(vec (concat (take n items) (drop (inc n) items))))
;;imperative
(defn input []
(flush)
(read))
(defn get-text []
(print "New text:")
(input))
(defn get-index []
(println "Which item?")
(dec (input)))
(defn main-loop [items]
(dorun (map-indexed (fn [i item]
(println (inc i) item))
items))
(println "(A)dd (E)dit (D)elete (S)ort (R)everse (Q)uit")
(case (input)
a (recur (add-item items (get-text)))
e (recur (edit-item items (get-index) (get-text)))
d (recur (delete-item items (get-index)))
s (recur (sort items))
r (recur (reverse items))
q nil))
(defn -main []
(println "Welcome to List Keeper!")
(main-loop []))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment