I wrote this goal:

(use 'clojure.core.logic)
(use 'clojure.core.logic.protocols)
 
(defn pluso [t1 t2 s]
  (fn goal [a]
    (let [args (map (partial walk a) [t1 t2 s])
          fresh? (map lvar? args)
          ground? (map not fresh?)
          [t1 t2 s] args]
      (cond
        (= [true  true  true ] ground?) (if (= s (+ t1 t2)) a nil)
        (= [true  true  false] ground?) (unify a s  (+ t1 t2))
        (= [true  false true ] ground?) (unify a t2 (- s t1))
        (= [false true  true ] ground?) (unify a t1 (- s t2))
        :else 
        a ;; Returning the substitution map will mark this goal as successful
          ;; while it is neither successful nor failed. The fresh variables
          ;; might be ground later.
        ))))


When I run this query I get (_0) while I'm expecting (3). The root of the 
problem is the returning of the substitution map if more than one variable 
is not ground.

(run* [q] 
  (fresh [a] 
    (pluso q 4 a)
    (== a 7)))


I've tried returning a choice but this leads to an endless loop.

Is it at all possible to somehow adapt the goal to await the grounding of 
the a-variable? What if the fresh variables are never ground?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to