Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding example and lein project file

  • Loading branch information...
commit d478286f699512ab5a3e360a2d1b9fa788c2a58a 1 parent fcdf7c8
@fogus fogus authored
View
3  .gitignore
@@ -1 +1,4 @@
target
+.lein*
+lib
+multi-lib
View
15 project.clj
@@ -0,0 +1,15 @@
+(defproject core.unify "0.6.0-SNAPSHOT"
+ :description "Clojure unification library."
+ :dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]
+ :dev-dependencies [[jline "0.9.94"]
+ [swank-clojure "1.4.2"]
+ [lein-marginalia "0.7.1"]
+ [lein-multi "1.1.0"]]
+ :multi-deps {"1.2" [[org.clojure/clojure "1.2.0"]]
+ "1.2.1" [[org.clojure/clojure "1.2.1"]]
+ "1.3" [[org.clojure/clojure "1.3.0"]]
+ "1.4" [[org.clojure/clojure "1.4.0"]]
+ "1.5" [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}
+ :repositories {"sonatype-oss-public" "https://oss.sonatype.org/content/groups/public/"}
+ :source-path "src/main/clojure"
+ :test-path "src/test/clojure")
View
37 src/main/clojure/clojure/core/unify.clj
@@ -222,3 +222,40 @@
" Note: This function is implemented **without** an occurs-check.")
:arglists '([expression1 expression2])}
unifier- (make-unifier-fn VARIABLE?))
+
+
+(comment
+
+ (def T '[?a ?b])
+
+ (defn make-matcher
+ [root]
+ (fn [tmpl req]
+ (-> req
+ :url
+ (.replace root "")
+ (.split "/")
+ seq
+ (unify- tmpl))))
+
+ (def match (make-matcher "http://foo.com/foo/"))
+
+ (match T {:url "http://foo.com/foo/1/2"})
+ ;;=> {?a 1, ?b 2}
+
+ (match T {:url "http://foo.com/foo/1"})
+
+ (defn make-genr
+ [root]
+ (fn [tmpl binds]
+ (->> binds
+ (subst tmpl)
+ (interpose "/")
+ (cons root)
+ (apply str))))
+
+ (def gen (make-genr "http://foo.com/foo/"))
+
+ (gen T '{?a 1, ?b 2})
+ ;=> "http://foo.com/foo/1/2"
+)
Please sign in to comment.
Something went wrong with that request. Please try again.