I am happy to announce the first release of stratege
<https://github.com/mschuene/stratege>.
stratege is a strategic term rewriting library inspired by StrategoXT that
provides composeable strategy combinators, is based on zippers and
internally uses continuation passing style, so that it doesn't throw stack
overflows on deeply nested terms.
The README.md on github gives the rationale and gets you started.
Below is an example for transforming boolean expressions into disjunctive
and conjunctive normal forms.
(require '[stratege.core :as s :refer [defrule rules]])
(defrule defi [:impl x y] -> [:or [:not x] y])
(defrule defe [:eq x y] -> [:and [:impl x y] [:impl y x]])
(defrule dn [:not [:not x]] -> x)
(defrule dma [:not [:and x y]] -> [:or [:not x] [:not y]])
(defrule dmo [:not [:or x y]] -> [:and [:not x] [:not y]])
(defrule daol [:and [:or x y] z] -> [:or [:and x z] [:and y z]])
(defrule daor [:and z [:or x y]] -> [:or [:and z x] [:and z y]])
(defrule doal [:or [:and x y] z] -> [:and [:or x z] [:or y z]])
(defrule doar [:or z [:and x y]] -> [:and [:or z x] [:or z y]])
(def dnf (s/innermost (rules dn defi defe dma dmo daol daor)))
(def cnf (s/innermost (rules dn defi defe dma dmo doal doar)))
(is (= (dnf [:or [:not [:or [:not :x] :y]] :z])
[:or [:and :x [:not :y]] :z]))
(is (= (cnf [:or [:not [:or [:not :x] :y]] :z])
[:and [:or :x :z] [:or [:not :y] :z]]))
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.