From 8a9a957a62605a8a3b0bef6cbd227a65edfe4a07 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Wed, 12 Jan 2011 16:38:04 -0600 Subject: [PATCH] Parse required clojure version out of project.clj to avoid duplication. --- project.clj | 2 +- src/path_to_enlightenment.clj | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/project.clj b/project.clj index 5d8bf0a..e514733 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject functional-koans "0.1.0" +(defproject functional-koans "0.2.0" :description "The functional koans" :dependencies [[org.clojure/clojure "1.3.0-alpha3"] [jline "0.9.94"]]) diff --git a/src/path_to_enlightenment.clj b/src/path_to_enlightenment.clj index 13408d3..a65f9ed 100644 --- a/src/path_to_enlightenment.clj +++ b/src/path_to_enlightenment.clj @@ -1,6 +1,7 @@ (ns path-to-enlightenment (:use [clojure.test]) - (:require [clojure.set])) + (:require [clojure.set] + [clojure.string])) (def __ nil) (def ___ (fn [& args] nil)) @@ -37,7 +38,20 @@ (throw (Exception. (str "Clojure version " required-major "." required-minor " or higher required.")))))) +(defn parse-required-version [] + (let [rdr (clojure.lang.LineNumberingPushbackReader. + (java.io.FileReader. (java.io.File. "project.clj"))) + project-form (read rdr) + version-string (->> project-form + (drop 3) + (apply hash-map) + :dependencies + (into {}) + ('org.clojure/clojure))] + (map read-string + (take 3 (clojure.string/split version-string #"[\.\-]"))))) + (defn run [] - (require-version [1 3]) + (require-version (parse-required-version)) (apply load (doall (map (partial str "koans/") ordered-koans))) (println "You have achieved clojure enlightenment. Namaste."))