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
限制的项目的集合。