str is a function not a goal/relation - it doesn't know how to deal with logic vars. If you want that to work you will need to project result first. But if you project result then order matters and the unification of query must come after the membero call.
On Thu, Apr 4, 2013 at 9:25 AM, Adam Saleh <adamthecam...@gmail.com> wrote: > Hi, I am trying to write myself something to generate some test data, and > I thought > clojure.core logic fits the bill ... unfortunately, for some reason, it > doesn't work. > > In my project.clj: > > [org.clojure/clojure "1.5.0"] > [org.clojure/core.logic "0.8.3"] > > in my namespace: > (ns tests.search > (:require > [clojure.set :refer [intersection difference union project select]] > [clojure.core.logic :as l])) > > (def search-table > ((fn [header table] (into #{} (map #(zipmap header %1) table))) > > [:title :type :severity] > [[ "Squirrel" "enhancement" "low"] > [ "Camel" "security" "important"] > [ "Dog" "security" "critical"] > [ "Cow" "bugfix" "moderate"]])) > > > Now, I try to generate pairs [query result] with logic programming. > > (l/run 1 [test-line] > (l/fresh [query result] > (l/== query ["\"" result "\""]) > (l/membero result (map :name (project errata-search-table [:name]))) > (l/== test-line [query result]))) > > >> ([["\"" "Squirrell" "\""] "Squirrell"]) > > But I can't figure out how to force query to unify to a string: > > (l/run 1 [test-line] > (l/fresh [query result] > (l/== query (str "\"" result "\"")) > (l/membero result (map :name (project errata-search-table [:name]))) > (l/== test-line [query result]))) > > >> (["\"<lvar:result__11616>\"" "Squirrell"]) > > When I asked on freenode, I got this response: > > <hyPiRion> asaleh: str is impure, using e.g. (fresh [x y] (== y (str x))) > won't work > > Thanks, > > Adam > > -- > -- > 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. > > > -- -- 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.