Here's another clojure.core.logic relation. This time for http://api.stlouisfed.org/docs/fred/series_observations.html
https://gist.github.com/3062006 Example: The dates and rates of the US 10-year Treasury note when the rates were less than they were on Monday. (clojure.pprint/pprint (sort-by :date (fred-test "DGS10" "2012-07-02"))) ;; ({:target "1.61", :date "2012-05-31", :value "1.59"} ;; {:target "1.61", :date "2012-06-01", :value "1.47"} ;; {:target "1.61", :date "2012-06-04", :value "1.53"} ;; {:target "1.61", :date "2012-06-05", :value "1.57"} ;; {:target "1.61", :date "2012-06-11", :value "1.60"} ;; {:target "1.61", :date "2012-06-15", :value "1.60"} ;; {:target "1.61", :date "2012-06-18", :value "1.59"} ;; {:target "1.61", :date "2012-06-28", :value "1.60"}) Not too many of those. --Jamie On Friday, July 6, 2012 9:16:09 AM UTC-5, Jamie wrote: Core.logic is great. Here's a trivial 10-line core.logic relation backed > by a Lucene index. Simple and useful (at least to us). Need a library of > such things. > > Comments and improvements appreciated. > > Details at https://gist.github.com/3060305 . > > The gist of the gist is: > > ;; Generate the Lucene query string. > (defn- lucene-query > "Query Lucene based on the given object and Substitutions. The > query Q should be a map that has some values bound by substitutions A. > The generated Lucene query string looks like 'p1:v1 AND p2:v2', where > Q contains :p1 lv1 and :p2 lv2 and the substitutions take lv1 to v1 and > lv2 to v2. That query string is then used in the Lucene query." > ([q a] > (db/search (index) > (reduce str > (interpose " AND " > (map (fn [[k v]] > (str (subs (str k) 1) ":" v)) > (remove (comp logic/lvar? last) > (logic/walk* a q))))) > (config :max-query-results)))) > > > ;; The core.logic relation. > > (defn lucenalog-rel [q] > "A clojure.core.logic relation backed by Lucene. Lucene query > generated by lucene-query based on the given map." > (fn [a] > (logic/to-stream > (map #(logic/unify a % q) > (lucene-query q a))))) > > --Jamie > > > -- 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