From b02095fd7f1133b9b531d259811d97aa6df5719f Mon Sep 17 00:00:00 2001 From: Eric Lavigne Date: Mon, 8 Feb 2010 10:20:49 +0800 Subject: [PATCH 1/3] Added leiningen-run to the project. Now you can run it with: lein run --- project.clj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project.clj b/project.clj index c4a7634..a9c3fa2 100644 --- a/project.clj +++ b/project.clj @@ -1,7 +1,9 @@ (defproject functional-koans "0.0.1" :description "The functional koans" + :script "koans/path_to_enlightenment.clj" :dependencies [[org.clojure/clojure "1.1.0"] [org.clojure/clojure-contrib "1.0-SNAPSHOT"] [jline "0.9.94"]] - :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"]] - :namespaces [koans]) \ No newline at end of file + :dev-dependencies [[lein-clojars "0.5.0-SNAPSHOT"] + [leiningen-run "0.3"]] + :namespaces [koans]) From 6defe87b0b8002a716cea755e0f726304693d30f Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Mon, 8 Feb 2010 12:29:31 +0800 Subject: [PATCH 2/3] adding about maps --- koans/about_maps.clj | 48 +++++++++++++++++++++++++++++++++ koans/path_to_enlightenment.clj | 3 ++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 koans/about_maps.clj diff --git a/koans/about_maps.clj b/koans/about_maps.clj new file mode 100644 index 0000000..9215453 --- /dev/null +++ b/koans/about_maps.clj @@ -0,0 +1,48 @@ +(meditations + "Maps in clojure associate keys with values" + (= __ (.size (hash-map))) + + "There are two ways to create maps" + (= {} (hash-map)) + + "A value must be supplied for each key" + (= {:a 1} (hash-map :a __)) + + "The size is the number of entries" + (= __ (.size {:a 1 :b 2})) + + "You can look up the value for a given key" + (= __ (get {:a 1 :b 2} :b)) + + "Maps can be used as lookup functions" + (= __ ({:a 1 :b 2} :a)) + + "And so can keywords" + (= __ (:a {:a 1 :b 2})) + + "But map keys need not be keywords" + (= __ ({2006 "Torino" 2010 "Vancouver" 2014 "Sochi"} 2010)) + + "You may not be able to find an entry for a key" + (= nil (get {:a 1 :b 2} :c)) + + "You can find out if a key is present" + (= __ (contains? {:a nil :b nil} :b)) + + "Or if it is missing" + (= __ (contains? {:a nil :b nil} :c)) + + "Maps are immutable, but you can create a new, 'changed' version" + (= {1 "January" 2 __} (assoc {1 "January" 2 "Febuary"} 2 "February")) + + "You can also 'remove' an entry" + (= {__ __} (dissoc {1 "January" 2 "February"} 2)) + + "Often you will need to get the keys (which will be in hash order)" + (= (list __ __ __) + (sort (keys {2006 "Torino" 2010 "Vancouver" 2014 "Sochi"}))) + + "Or the values" + (= (list "Sochi" "Torino" __) + (sort (vals {2006 "Torino" 2010 "Vancouver" 2014 "Sochi"})))) + diff --git a/koans/path_to_enlightenment.clj b/koans/path_to_enlightenment.clj index e8b9d62..e0934f7 100644 --- a/koans/path_to_enlightenment.clj +++ b/koans/path_to_enlightenment.clj @@ -15,4 +15,5 @@ (load "about_equalities") (load "about_vectors") (load "about_sets") -(println "You have acheived clojure enlightenment. Namaste.") \ No newline at end of file +(load "about_maps") +(println "You have acheived clojure enlightenment. Namaste.") From 012d86b38279e42e99c6606be17cb0fb47b1f6d4 Mon Sep 17 00:00:00 2001 From: Aaron Bedra Date: Mon, 8 Feb 2010 00:25:18 -0500 Subject: [PATCH 3/3] updating readme and removing runner since lein run works now --- README.markdown | 4 +--- path_to_enlightenment | 9 --------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100755 path_to_enlightenment diff --git a/README.markdown b/README.markdown index 8d2b125..b71b222 100644 --- a/README.markdown +++ b/README.markdown @@ -14,6 +14,4 @@ which will download all dependencies you need to run the clojure koans. To run the koans, simply run -path_to_englightenment - -which will start path_to_enlightenment.clj. +lein run diff --git a/path_to_enlightenment b/path_to_enlightenment deleted file mode 100755 index dfba636..0000000 --- a/path_to_enlightenment +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -CLASSPATH=. - -for f in lib/*.jar; do - CLASSPATH=$CLASSPATH:$f -done - -java -cp $CLASSPATH clojure.main -i koans/path_to_enlightenment.clj