Skip to content

@sharat87 /README.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Operating System dependent dispatch of multimethods in clojure

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.

(ns main
(:use utils))
(require (case current-os
:linux 'utils-linux
:windows 'utils-windows))
(where-am-i)
(ns utils)
(def current-os (-> (System/getProperty "os.name")
.toLowerCase
keyword))
(defmulti where-am-i
(fn [& _] current-os))
(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.