Skip to content

Instantly share code, notes, and snippets.

@kahunamoore
Created January 15, 2014 06:33
Show Gist options
  • Save kahunamoore/8431800 to your computer and use it in GitHub Desktop.
Save kahunamoore/8431800 to your computer and use it in GitHub Desktop.
Odd rule binding behavior
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
(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))))
(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