You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Clojure中case表达式解引用atom为何返回结果不符合预期?

Clojure case表达式匹配疑问

以下代码返回true:

(def a (atom 1))
(case @a 1 true false)

但以下代码返回false:

(def a (atom 1))
(case 1 @a true false)

第二个表达式难道不应该返回true吗?


解答:
@Carcigenicate的解释:case的每个分支匹配值都必须是编译时常量。

@a并非编译时常量,因此该case表达式需替换为if表达式:

(def a (atom 1))
(if (= 1 @a) true false)

内容的提问来源于stack exchange,提问作者Francois

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 13:16:00