Permalink
Browse files

Upgrade to Kibit new-rules (9be5f26).

  • Loading branch information...
1 parent 1bbdac1 commit 776e87ecb2cc43d9f961fbcfe653863a7ef3ecb2 @lynaghk committed Apr 1, 2012
Showing with 145 additions and 17 deletions.
  1. +137 −11 scratch.clj
  2. +4 −1 src/cljx/core.clj
  3. +4 −5 src/cljx/rules.clj
View
@@ -1,7 +1,7 @@
(ns scratch
(:use [cljx.core :only [generate]]
[cljx.rules :only [cljs-rules clj-rules]]
- :reload))
+ :reload-all))
(do
(def cljx-path "test/cljx")
@@ -16,30 +16,156 @@
(comment
(set! *print-meta* false)
(use 'clojure.stacktrace)
-
+
(do
(generate cljx-path cljs-output-path "cljs" cljs-rules)
(generate cljx-path clj-output-path "clj" clj-rules))
+ (use '[clojure.java.io :only [reader]])
+
+ (let [r (reader (java.io.File. "test/cljx/testns/core.cljx"))]
+ (kibit.check/check-reader r
+ :rules cljs-rules
+ :guard identity
+ :resolution :toplevel))
+
+
+
+ (use '[kibit.core :only [simplify simplify-one]])
+ (use 'clojure.core.logic)
+
+ (defn simplify-one [expr rules]
+ (let [alt (run* [q]
+ (fresh [pat subst]
+ (membero [pat subst] rules)
+ (project [pat subst]
+ (all (pat expr)
+ (subst q)))))]
+ (if (empty? alt) expr (first alt))))
+ (def form '(defmacro nom [x] (some (delicious)) forms))
+
+ ;;this works nicely
+ (let [x (lvar)
+ rest (lvar)]
+ (run* [q]
+ (== form (llist 'defmacro x rest))
+ (== q x)))
+ ;;=> (nom)
+ ;;why not this?
+ (let [x (lvar)
+ rest (lvar)]
+ (run* [q]
+ (== form (defmacro ~x . ~rest))
+ (== q x)))
+ ;;=> ()
+ ;;This doesn't work either
+ (run* [q]
+ (prep '(all
+ (== form '(defmacro ?x . ?rest))
+ (== q ?x))))
+ ;;=> java.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to clojure.lang.IFn
- (use '[kibit.core :only [simplify simplify-one]]
- 'clojure.core.logic)
- (simplify-one '(defmacro nom [x] nom nom nom)
- [[#(matche [%]
- ([['defmacro . _]]))
- #(== % :exclude)]])
+ ;;This also works
(run* [q]
- (firsto '(defmacro nom [x] nom nom nom) 'defmacro)
-)
+ (fresh [pat alt]
+ (membero [pat alt]
+ [(prep '[(defmacro ?x . ?rest)
+ ?x])])
+ (== pat form)
+ (== q alt)))
+ ;;=> (nom)
+
+
+
+ (run* [q]
+ (all
+ (== form (prep '(defmacro ?x . ?rest)))
+ (== q true)))
+
+ (clojure.core/doall
+ (clojure.core.logic/solve false [q]
+ (all
+ (== form (prep (quote (defmacro ?x . ?rest))))
+ (== q true))))
+
+
+ (clojure.core/doall
+ (clojure.core.logic/solve false [q]
+ (eval (prep (quote (all
+ (== form (defmacro ?x . ?rest))
+ (== q true)))))))
+ (run* [q]
+ (prep '(all
+ (== form (defmacro ?x . ?rest))
+ (== q true))))
+;;why not this?
+ (run* [q]
+ (fresh [pat alt]
+ (membero [pat alt]
+ [(prep '[#(== % (defmacro ?x . ?rest))
+ #(== % ?x)])])
+ (pat form)
+ (alt q)))
+ ;;=> clojure.core.logic.LVar cannot be cast to clojure.lang.IFn
+
+
+
+
+
+
+
+ (simplify-one form
+ [(fresh [pat alt]
+ (== [pat alt]
+ (prep '[(defmacro ?x . ?rest) #(== % ?x)]))
+ [#(== pat %)
+ alt])])
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (simplify-one form
+ [[#(matche [%]
+ ([['defmacro . _]]))
+ #(== % :exclude)]])
+
+
+
+
+ (def inc-rule
+ (let [x (lvar)]
+ [#(all (== % `(~'+ ~x 1))
+ ;; It's easy to add pattern predicates
+ (pred x number?))
+ #(== % `(inc ~x))]))
+
+
+
+
+ (let [x (lvar)
+ rest (lvar)]
+ `(~'defmacro ~x . ~rest)
+ )
+
+
(defn ns->cljs-ns
"Creates a cljs-compatible namespace form by splitting vars marked with ^:macro into appropriate use-macros or require-macros forms"
[ns-form]
@@ -55,4 +181,4 @@
(require '[clojure.core.logic :as logic])
- )
+
View
@@ -25,7 +25,10 @@ Returns a sequence of File objects, in breadth-first sort order."
(defn munge-forms
[reader rules]
- (->> (kibit.check/check-toplevel-forms reader rules)
+ (->> (kibit.check/check-reader reader
+ :rules rules
+ :guard identity
+ :resolution :toplevel)
(map #(or (:alt %) (:expr %)))
(remove #(= % :cljx.core/exclude))))
View
@@ -1,6 +1,7 @@
(ns cljx.rules
(:refer-clojure :exclude [==])
- (:use [clojure.core.logic :only [matche conde pred lvar == firsto]]))
+ (:use [clojure.core.logic :only [matche conde pred lvar == firsto]]
+ [kibit.rules.util :only [compile-rule]]))
(defn- meta-guard [key]
#(-> % meta key (= true)))
@@ -22,12 +23,10 @@
#(== % x)]))
(def remove-defmacro
- [#(firsto % 'defmacro)
- #(== % :cljx.core/exclude)])
+ (compile-rule '[(defmacro . ?_) :cljx.core/exclude]))
(def remove-comment
- [#(firsto % 'comment)
- #(== % :cljx.core/exclude)])
+ (compile-rule '[(comment . ?_) :cljx.core/exclude]))

0 comments on commit 776e87e

Please sign in to comment.