评论者: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 行为造成轻微偏差。有什么看法?