Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created November 23, 2012 21:21
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 hugoduncan/4137374 to your computer and use it in GitHub Desktop.
Save hugoduncan/4137374 to your computer and use it in GitHub Desktop.
An issue with core.logic prep?
(run* [q]
(fresh [pattern production guards rule rule-name]
(membero
{:pattern pattern :production production}
[{:pattern (partial-map {:a :clojure.core.logic/not-found :x 1})
:production {:a 1}}
{:pattern (partial-map {:a '?a :c :clojure.core.logic/not-found})
:production {:c '(* ?a 2)}}])
(== {:x 1} pattern)
(== q production)))
=> ({:a 1})
(run* [q]
(fresh [pattern production guards rule rule-name]
(membero
{:pattern pattern :production production}
[{:pattern (partial-map (prep {:a :clojure.core.logic/not-found :x 1}))
:production {:a 1}}
{:pattern (partial-map (prep {:a '?a :c :clojure.core.logic/not-found}))
:production {:c '(* ?a 2)}}])
(== {:x 1} pattern)
(== q production)))
=> ({:a 1} {:c (* ?a 2)})
@hugoduncan
Copy link
Author

The above are identical apart from the use of prep.

@hugoduncan
Copy link
Author

(let [rules
      [{:pattern (partial-map (prep {:a :clojure.core.logic/not-found :x 1}))
        :production {:a 1}}
       {:pattern (partial-map (prep {:a '?a :c :clojure.core.logic/not-found}))
        :production {:c '(* ?a 2)}}]]
  (run* [q]
    (fresh [pattern production guards rule rule-name]
      (membero {:pattern pattern :production production} rules)
      (== {:x 1}  pattern)
      (== q production))))
  => ({:a 1} {:c (* ?a 2)})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment