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