Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Operating System dependent dispatch of multimethods in clojure

View README.md

This is me trying out clojure's multimethods for a problem I'm trying to solve. See this Stack Overflow question for follow up.

Note that implementation namespaces are named utils-linux and utils-windows instead of utils.linux and utils.windows because Gists can't have subdirectories.

View README.md
1 2 3 4 5 6 7 8
(ns main
(:use utils))
 
(require (case current-os
:linux 'utils-linux
:windows 'utils-windows))
 
(where-am-i)
View README.md
1 2 3 4 5 6 7 8
(ns utils)
 
(def current-os (-> (System/getProperty "os.name")
.toLowerCase
keyword))
 
(defmulti where-am-i
(fn [& _] current-os))
View README.md
1 2 3 4 5 6
(ns utils-linux
(:use utils))
 
(defmethod where-am-i :linux
[]
(prn (str "I am running on " (System/getProperty "os.name"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.