core.logic

Usage of c.c.l/prep can lead to a different result (compared to not using it)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • 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})

Activity

David Nolen made changes -
Field Original Value New Value
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Hide
Hugo Duncan added a comment -

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.

Show
Hugo Duncan added a comment - 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.
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: