Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect operating system in Clojure

Is there an equivalent of Common Lisp's *features* in Clojure, so you can detect the OS and other environment configuration? Or do I just go through the Java API for that?

like image 753
justinhj Avatar asked Jan 24 '11 18:01

justinhj


2 Answers

Probably use the Java API. It's easy enough, no sense re-inventing the wheel.

user> (System/getProperty "os.name")
"Linux"
user> (System/getProperty "os.version")
"2.6.36-ARCH"
user> (System/getProperty "os.arch")
"amd64"
like image 52
Brian Carper Avatar answered Oct 22 '22 18:10

Brian Carper


To add to Brian Carper's answer, you could easily create a map of system properties via the Java API and bind it to the symbol features:

(def *features* {
  :name (System/getProperty "os.name"),
  :version (System/getProperty "os.version"),
  :arch (System/getProperty "os.arch")})

Which gives you this structure, for example:

{:name "Windows 7", :version "6.1", :arch "x86"}

Then access a property in any one of the following ways:

(:name *features*)
(*features* :name)
(get *features* :name)

Whichever floats your boat.

like image 5
semperos Avatar answered Oct 22 '22 18:10

semperos