Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Document how defn/implicit do with multiple goals does not work
Description
Hi! I have a small documentation improvement proposal:
When using regular `defn` to create a relation, I've found that an empty (fresh [] ...) is needed if you want to use multiple relations and goals inside your defn:ed relation, otherwise your goals are in the implicit do from defn, and only the last one has any effect.
Simple example:
{{ defn-logic> (defn test [a b] (== a 1) (== b 2)) #'defn-logic/test defn-logic> (run* [q] (fresh [a b] (== q [a b]) (test a b))) ([_0 2]) defn-logic> (defn test [a b] (fresh [] (== a 1) (== b 2))) #'defn-logic/test defn-logic> (run* [q] (fresh [a b] (== q [a b]) (test a b))) ([1 2]) defn-logic> }}
Again, this is perfectly correct and reasonable, but maybe a bit confusing for beginners, in that the implicit do "fails silently". What I'm looking for here is probably just a heads up in the Wiki docs. I couldn't find it, but maybe it exists already? I'd be happy to add it to the documentation and send a PR.
Hi! I have a small documentation improvement proposal:
When using regular `defn` to create a relation, I've found that an empty
(fresh [] ...)
is needed if you want to use multiple relations and goals inside your defn:ed relation, otherwise your goals are in the implicit do from defn, and only the last one has any effect.Simple example:
{{
defn-logic> (defn test [a b]
(== a 1)
(== b 2))
#'defn-logic/test
defn-logic> (run* [q] (fresh [a b]
(== q [a b])
(test a b)))
([_0 2])
defn-logic> (defn test [a b]
(fresh []
(== a 1)
(== b 2)))
#'defn-logic/test
defn-logic> (run* [q] (fresh [a b]
(== q [a b])
(test a b)))
([1 2])
defn-logic>
}}
Again, this is perfectly correct and reasonable, but maybe a bit confusing for beginners, in that the implicit do "fails silently". What I'm looking for here is probably just a heads up in the Wiki docs. I couldn't find it, but maybe it exists already? I'd be happy to add it to the documentation and send a PR.