为什么逻辑 "and" 谓词不起作用?

Why logical "and" predicates do not work?

datascript 1.3.0

上测试

原子数:

[{:db/id -1 :name "Smith" :firstname "Oliver" :age 20}
 {:db/id -2 :name "Jones" :firstname "Oliver" :age 20}
 {:db/id -3 :name "Smith" :firstname "Amelia" :age 16}
 {:db/id -4 :name "Jones" :firstname "Amelia" :age 16}]

尝试使用下面的逻辑 and 谓词查询名为 Smith 且年龄超过 18 岁的人,为什么 return 未过滤的整个集合?

'[:find ?firstname ?name
  :where
  [?p :name ?name]
  [?p :firstname ?firstname]
  [?p :age ?age]
  [(and (= ?name "Smith") (> ?age 18))]]

;;; wrong result: #{[Oliver Smith] [Oliver Jones] [Amelia Smith] [Amelia Jones]}

然后改为使用离散谓词查询,得到了预期的满意结果。

'[:find ?firstname ?name
  :where
  [?p :name ?name]
  [?p :firstname ?firstname]
  [?p :age ?age]
  [(= ?name "Smith")]
  [(> ?age 18)]]

;;; correct result: #{[Oliver Smith]}

datomicdatascriptdatalog通常只支持分散到离散子句的数据模式吗?常规逻辑运算and等在这里不兼容吗?

根据 the manual,您不能像那样使用 and-clause。您可以使用 and-clause 的唯一方法是当它位于 or-clause:

中时

Inside the or clause, you may use an and clause to specify conjunction. This clause is not available outside of an or clause, since conjunction is the default in other clauses.

这是因为 AND 是隐含的。所有子句都由 AND 隐式连接,因为它们必须同时为真才能使查询匹配