【发布时间】:2013-08-14 15:41:36
【问题描述】:
编辑: 在发布我的问题的先前版本后,我发现真正的问题在于嵌套函数。
如果我在 deftype 中有一个闭包,我将无法从该闭包中更新任何可变字段。
例如以下作品:
(deftype Test [^:unsynchronized-mutable x]
TestInterface
(perform [this o] (set! x o)))
但事实并非如此:
(deftype Test [^:unsynchronized-mutable x]
TestInterface
(perform [this o] (fn [] (set! x o)) nil)) ; throws a compiler error about assigning to non-mutable field
有什么方法可以到达并进入该领域?执行(set! (.x this) o) 会导致:
ClassCastException user.Test 无法强制转换为 compile__stub.user.Test user.Test/fn--152 (NO_SOURCE_FILE:3
尝试运行代码时。
为了完整性,TestInterface 的代码:
(definterface TestInterface (perform [o]))
【问题讨论】:
-
能否包含 TestInterface 以便我运行示例?
-
@ArthurUlfeldt 我已经更新了问题并添加了 TestInterface。
-
这看起来像一个错误?什么版本的clojure?
-
clojure 版本 1.5.1