Datomic中的参数查询

noa*_*hlz 5 clojure datomic

我正在学习Datomic查询,并对如何进行"参数查询"感到好奇.

这就是我想出的:

(d/q '[:find ?n ?x :where [?n :likes ?x] [(= ?x "pizza")]] 
  [['ethel :likes "sushi"]['fred :likes "pizza"]])

=> #<HashSet [[fred "pizza"]]>
Run Code Online (Sandbox Code Playgroud)

这是它,还是有更简洁/惯用的方式来实现上述目标?

noa*_*hlz 6

答案在Datomic教程的 "高级查询"部分

使用该:in条款

(d/q '[:find ?n ?x :in $ ?x :where [?n :likes ?x]] 
  [['ethel :likes "sushi"]['fred :likes "pizza"]] "sushi")

=> #<HashSet [[ethel "sushi"]]>
Run Code Online (Sandbox Code Playgroud)

:in $ ?x是参数子句,并且尾随"sushi"绑定?x