Last active
December 14, 2015 06:09
-
-
Save drcode/5040624 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
(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