clojure.core.core。在嵌套地图上

发布于 2025-01-26 20:04:38 字数 348 浏览 2 评论 0原文

在clojure.core.match中,此示例在嵌套地图中效果很好,

(match [{:a {:b :c}}]
  [{:a {:b nested-arg}}] nested-arg)

但是当将更改为vector时,它会引起错误。

(m/match x
  {:a {[:b :c]  1}}
  :found
  )

那不是[:b:c]是clojure地图中的有效键吗?否则它只是在clojure.core.match中无法使用?

in clojure.core.match , this example works well in nested map

(match [{:a {:b :c}}]
  [{:a {:b nested-arg}}] nested-arg)

but when change the key to a vector it will raise error.

(m/match x
  {:a {[:b :c]  1}}
  :found
  )

Isn't that [:b :c] is a valid key in clojure map ? Or it just won't work in clojure.core.match ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自演自醉 2025-02-02 20:04:38

[:b:c]当然是有效的键。这是一个错误,已经报告了,请参见打开问题

看来您也不能将映射与数字匹配为键:

(match/match [{:a 4}]
             [{:a _}] :found)
         
=> :found

(match/match [{2 4}]
             [{2 _}] :found)
         
Unexpected error (ClassCastException) macroexpanding match/match at ....
class java.lang.Long cannot be cast to class clojure.lang.Named (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.Named is in unnamed module of loader 'app')

[:b :c] is of course a valid key. This is a bug and it was already reported, see opened issue.

And it seems you can't also match map with numbers as keys:

(match/match [{:a 4}]
             [{:a _}] :found)
         
=> :found

(match/match [{2 4}]
             [{2 _}] :found)
         
Unexpected error (ClassCastException) macroexpanding match/match at ....
class java.lang.Long cannot be cast to class clojure.lang.Named (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.Named is in unnamed module of loader 'app')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文