Detect operating system in Clojure

感情迁移 提交于 2019-12-22 01:58:56

问题


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?


回答1:


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"



回答2:


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.




回答3:


Other answers are handling how to get the system info from Java pretty well. If you want more help interpreting it, here are some examples of how Terracotta did that:

  • VendorVmSignature
  • VmVersion
  • Vm


来源:https://stackoverflow.com/questions/4785937/detect-operating-system-in-clojure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!