Skip to content

Instantly share code, notes, and snippets.

@tiensonqin
Forked from eraserhd/forall.clj
Created February 18, 2021 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiensonqin/0b78319b52af4e95e5a20c5c96faba1c to your computer and use it in GitHub Desktop.
Save tiensonqin/0b78319b52af4e95e5a20c5c96faba1c to your computer and use it in GitHub Desktop.
;; Because in formal logic, ∀x.P(x) = ¬∃x.¬P(x)
(d/q '[:find ?id
:in $ [?interest ...]
:where
[?a :account/id ?id]
(not-join [?a ?interest]
[?a :account/interest ?i]
(not [(= ?i ?interest)]))])
;; It is harder to understand when you bind interest as above if you
;; are thinking in terms of iterative binding (but it still should
;; work!) If you make 'interests' a data source, it looks like this:
(d/q '[:find ?id
:in $ $interests
:where
[?a :account/id ?id]
(not-join [?a]
[?a :account/interest ?i]
(not [$interests ?i]))]
db
(map vector interests))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment