core.logic

Document how defn/implicit do with multiple goals does not work

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Environment:
    Clojure 1.8
    core.logic 0.8.10

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.

Activity

Hide
Oskar Wickstrom added a comment -

The REPL session got messed up, now attached as a file instead.

Show
Oskar Wickstrom added a comment - The REPL session got messed up, now attached as a file instead.
Hide
Oskar Wickstrom added a comment -

Oh, I just found `all` (http://clojuredocs.org/clojure.core.logic/all) which seems to be preferred over `(fresh [] ...)`.

Show
Oskar Wickstrom added a comment - Oh, I just found `all` (http://clojuredocs.org/clojure.core.logic/all) which seems to be preferred over `(fresh [] ...)`.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: