<< Back to previous view

[LOGIC-108] featurec or something similar to provide recursive partial partial map constraints Created: 24/Jan/13  Updated: 28/Jul/13  Resolved: 17/Mar/13

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

Type: Enhancement Priority: Major
Reporter: Kevin Downey Assignee: David Nolen
Resolution: Completed Votes: 0
Labels: None


 Comments   
Comment by David Nolen [ 24/Jan/13 3:58 PM ]

Basically, it should be ok for the `fs` argument to a be a nested map.

Comment by Kevin Downey [ 26/Jan/13 6:03 PM ]

the following seems to be pretty close:

    (defn rfeaturec [m f]
      (let [new-f (reduce (fn [m [k v]]
                            (assoc m k (logic/lvar (name k)))) {} (seq f))]
        (logic/fresh []
          (logic/featurec m new-f)
          (fn [s]
            (logic/to-stream
              (for [[k lvar] new-f]
                ((let [v (get f k)]
                   (if (map? v)
                     (logic/fresh [x]
                       (logic/featurec m {k lvar})
                       (rfeaturec lvar v))
                     (logic/== lvar v))) s)))))))
Comment by Kevin Downey [ 27/Jan/13 12:13 AM ]

the above falls apart quickly under use, the below works well so far:

(defn rfeaturec [m f]
  (let [new-f (reduce (fn [m [k v]] (assoc m k (logic/lvar (name k)))) {} (seq f))]
    (logic/fresh []
      (logic/featurec m new-f)
      (logic/everyg
       (fn [[k lvar]]
         (let [v (get f k)]
           (if (map? v)
             (logic/fresh []
               (logic/featurec m {k lvar})
               (rfeaturec lvar v))
             (logic/== lvar v))))
       new-f))))
Comment by David Nolen [ 27/Jan/13 6:43 PM ]

recursive featurec should work by recursively applying constraints like you've done but by using the lower level apis - we don't want to put the search language into a constraint.

Comment by David Nolen [ 17/Mar/13 7:50 PM ]

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

Generated at Mon Sep 15 22:03:22 CDT 2014 using JIRA 4.4#649-r158309.