<< Back to previous view

[LOGIC-73] Usage of c.c.l/prep can lead to a different result (compared to not using it) Created: 23/Nov/12  Updated: 28/Jul/13  Resolved: 23/Nov/12

Status: Closed
Project: core.logic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Hugo Duncan Assignee: David Nolen
Resolution: Completed Votes: 0
Labels: None


 Description   

Below are two expressions that differ only in the use of c.c.l/prep. When using prep there is an extra term returned, that includes a free ?a, which seems wrong, considering the second pattern should unify on the :a key.

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


 Comments   
Comment by David Nolen [ 23/Nov/12 4:34 PM ]

fixed, http://github.com/clojure/core.logic/commit/9a964d6c744433825332dd82370cb46eac7919da

Comment by Hugo Duncan [ 23/Nov/12 10:03 PM ]

The code in the prep case above contains a bug. Both the pattern and production should both be passed in a single call to prep, otherwise they end up with different logic vars. When corrected there is only one term returned when using prep.

I'm not sure what this means for the necessity or correctness of the fix.

Generated at Sun Oct 26 00:59:58 CDT 2014 using JIRA 4.4#649-r158309.