From https://github.com/tonsky/datascript
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
4)
pr-str
js/console.log)
;;; ([:red [20 30 40 50] [10 20 30 40]] [:blue [7 8] [7 8]])
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
3)
pr-str
js/console.log)
;;; ([:red [30 40 50] [10 20 30]] [:blue [7 8] [7 8]])
(->
(d/q '[:find ?color (max ?amount ?x) (min ?amount ?x)
:in [[?color ?x]] ?amount]
[[:red 10] [:red 20] [:red 30] [:red 40] [:red 50]
[:blue 7] [:blue 8]]
2)
pr-str
js/console.log)
;;; ([:red [40 50] [10 20]] [:blue [7 8] [7 8]])
因此,这不是一个关于它在做什么的问题,而是一个关于它如何(或至少为什么)这样做的问题。 max 和 min 是分别返回其后续整数的最大值或最小值的函数。 ?amount
如何成为限制聚合计数的因素?为什么这些东西会聚集在一起?代码如何运行以使其聚合。我真的不明白这段代码是如何生成它所产生的结果的。
最佳答案
max
和 min
为 overloaded在数据原子查询中。
一元 (min ?x)
和 (max ?x)
函数聚合返回单个数字。
二进制 (min ?n ?x)
和 (max ?n ?x)
函数聚合以返回长度受 ? 限制的项目集合? n
.
关于clojure - 为什么此数据记录查询会聚合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26952424/