什么是在clojure中实现这一目标的更有效方法:
(defn ones
([n] (ones n 1 1))
([n i res]
(if (< i n)
(recur n (inc i) (bit-set res i))
res)))
当涉及到数字类型时,它应该仍然"做正确的事".
我正在开发一个热升级功能,需要打包一个结构数组,以便为新版本找到它们.我真的想避免为每个可能的版本转换添加转换函数.这合理吗?
对结构的最可能的更改是将来要将更多字段添加到结构中,如果发生这种情况,则可以使用新字段的默认值.我还将很快面临将结构数组保存到配置文件中的任务,因此可以应用于热升级和配置保存的答案可以获得额外的功劳.
我不必担心热更新机制我只是给它一个指针和一个大小,它做了梦幻般的魔术:)
我想在巨大的遗留C应用程序中添加一些基于Java(实际上是Clojure)的事件处理程序.这样做最直接,最容易维护的方法是什么?我希望Java类在与C代码相同的过程中运行.这甚至可能吗?
我正在编写一个轻量级序列化函数,需要在其中包含两个可变大小的数组.
编辑:结果必须是连续的内存块
加载此项目时:
(defproject incanter "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]
[incanter "1.3.0"]]
:dev-dependencies [[swank-clojure/swank-clojure "1.4.0"]])
Run Code Online (Sandbox Code Playgroud)
并像这样使用它:
(use '(incanter stats))
Run Code Online (Sandbox Code Playgroud)
我收到这个神秘的错误消息:
$ does not exist
[Thrown class java.lang.IllegalAccessError]
... lots-o-stack ...
Run Code Online (Sandbox Code Playgroud) 我有这个宏来捕捉一个特别讨厌的VMware bug(如果你重新连接就会消失)
(defmacro with-mib-workaround
"this macro exists because vCenter sometimes fails to get the
managed object reference for objects that actually do exist. Wrap
any call to vi java in this to have it retry with an incramental delay"
[& body]
`((fn mib-workaround# [attempt# timeout#]
(if (> attempt# 10)
(do (println "giving up after too many mib-not-found failures")
(println "please complain to VMware about this bug...")
(throw (Exception. "MIB not found for existing object")))
(try
~@body
(catch com.vmware.vim25.ManagedObjectNotFound e#
(println …Run Code Online (Sandbox Code Playgroud)