Skip to content

Instantly share code, notes, and snippets.

@bostonaholic
Created October 29, 2011 03:53
Show Gist options
  • Save bostonaholic/1324048 to your computer and use it in GitHub Desktop.
Save bostonaholic/1324048 to your computer and use it in GitHub Desktop.
Include clojure 1.3.0 libraries for emacs clojure-jack-in
;; ~/.lein/user.clj
(if (>= (.compareTo (clojure-version) "1.3.0") 0)
(do (use 'clojure.repl)
(use 'clojure.java.javadoc)
(use 'clojure.reflect)))
@sergeyklay
Copy link

(defn- normalize-verison
  [version]
  (let [[x y z] (map read-string (clojure.string/split version #"\."))
        z (or z 0)]
    (+ (* x 10000) (* y 100) z)))

(defn version-compare
  [a b]
  (let [left (normalize-verison a)
        right (normalize-verison b)]
    (cond
      (< left right) -1
      (> left right)  1
      :else           0)))


(version-compare "1.3.1" "1.3.0")
;; 1 
(version-compare "1.3.1" "1.3.2")
;; -1 
(version-compare "1.3.1" "1.3.1")
;; 0 
(version-compare "1.10.1" "1.3.0")
;; 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment