-
-
Save lynaghk/2206272 to your computer and use it in GitHub Desktop.
A more advanced rule system?
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 termite.core | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic])) | |
(defn- meta-guard [key] | |
#(do | |
(println % ":\t" (meta %)) | |
(-> % meta key (= true)))) | |
;;remove anything that has {:clj true} metadata, including on var declarations. | |
(def cljs-rule | |
[#(matcha [%] | |
([[_ var . _]] | |
(pred var (meta-guard :clj))) | |
([x] | |
(pred x (meta-guard :clj)))) | |
#(== % :exclude)]) | |
(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)))) | |
(set! *print-meta* true) | |
(doall (map #(simplify-one % [cljs-rule]) | |
['(defn ^:clj x [] 123) | |
'(defn ^:cljs stays [] 123) | |
(quote ^:clj a-var) | |
(quote ^:clj (a-form)) | |
'(stays) | |
])) | |
;;Metadata is getting dropped somewhere in the matcha: | |
;; x : {:clj true} | |
;; stays : {:cljs true} | |
;; (defn stays [] 123) : nil | |
;; a-var : {:clj true} | |
;; (a-form) : nil | |
;; (stays) : nil | |
;;=> (:exclude ^{:line 1} (defn ^{:cljs true} stays [] 123) :exclude ^{:clj true, :line 1} (a-form) ^{:line 1} (stays)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@swannodette, I dug into core.logic a bit to see what's what, but didn't get very far.
I don't know a ton about metadata, but presumably in a destructuring somewhere there is a seq fn that doesn't preserve it?