评论者:aralo
因此,CLJ 的 tickets 中的问题在 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 orig)
(fn outer [n]
(pr "outer")
(orig n))))
(self-call-test 2)
(def self-call-test2 self-call-test)
(fn self-call-test2
[n]
(prn "inner")
(when (pos? n)
(self-call-test2 (dec n)))))
(let [orig self-call-test2]
(set! self-call-test2 orig)
(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"
对于两个都适用。鉴于这一点,为了避免在生产环境中难以追踪的用户生产中的 bugs,最好在高级构建期间不更改行为。即使这与 CLJ 行为略有偏差。您怎么看?