Created
January 15, 2014 06:33
-
-
Save kahunamoore/8431800 to your computer and use it in GitHub Desktop.
Odd rule binding behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v: c ?e1: ?e2: puzzle.core.Entry@ebe1e4be | |
v: c ?e1: ?e2: puzzle.core.Entry@ebe1e4be | |
v: c ?e1: ?e2: puzzle.core.Entry@ebe1e4be | |
v: c ?e1: ?e2: puzzle.core.Entry@ebe1e4be | |
v: b ?e1: ?e2: puzzle.core.Entry@ebe1e4bf | |
v: a ?e1: ?e2: puzzle.core.Entry@ebe1e4bc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns puzzle.core | |
(:refer-clojure :exclude [==]) | |
(:require [clara.rules :refer :all])) | |
(defrecord Entry [value]) | |
(defrule make-uniqueness | |
"Convert a collection of strings, with duplicates, into a collection of unique strings with no duplicates - appending numbers as needed." | |
[?e1 <- Entry (== ?v value)] | |
[?e2 <- Entry (== ?v value)] | |
[:test (not (identical? ?e1 ?e2))] | |
=> | |
(println (str "v: " ?v " ?e1: " ?e1 " ?e2: " ?e2))) | |
(defn -main | |
"Run the uniqer." | |
[& args] | |
;; Create a session | |
(let [session (mk-session 'puzzle.core)] | |
(-> session | |
(insert | |
(->Entry "a") | |
(->Entry "b") | |
(->Entry "c") | |
(->Entry "c")) | |
(fire-rules)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defproject puzzle "0.1.0-SNAPSHOT" | |
:description "FIXME: write description" | |
:url "http://example.com/FIXME" | |
:license {:name "Eclipse Public License" | |
:url "http://www.eclipse.org/legal/epl-v10.html"} | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[org.toomuchcode/clara-rules "0.3.0"]] | |
:main "puzzle.core") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment