由:aralo
因此,CLJ票据中的问题在以下CLJS中模拟/显示
`
(enable-console-print!)
(defn self-call-test
[n]
(prn "inner")
(when (pos? n)
(self-call-test (dec n))))
(let [orig self-call-test]
(set! self-call-test
(fn outer [n]
(pr "outer")
(orig n))))
(self-call-test 2)
(def self-call-test2
(fn self-call-test2
[n]
(prn "inner")
(when (pos? n)
(self-call-test2 (dec n)))))
(let [orig self-call-test2]
(set! self-call-test2
(fn outer [n]
(pr "outer")
(orig n))))
(self-call-test2 2)
`
在没有优化的情况下输出
`
"outer"
"inner"
"outer"
"inner"
"outer"
"inner"
"outer"
"inner"
"inner"
"inner"
`
因此:这似乎会破坏当前的行为,但是,上述高级优化提供了以下内容
"outer" "inner" "inner" "inner"
对于两种。鉴于这一点,似乎最好在高级构建期间不更改行为,以避免为用户查找难以追踪的生产错误。即使这与CLJ行为略有偏差。有什么看法?