https://mobile.twitter.com/sritchie/status/1385354524034887681
Merged a change last night that makes all of this compatible with SCI, macros and all!
I’ll probably pull it out into its own library. @borkdude there is a bit of ceremony required to make the namespaces available, replace macros etc - I wonder if that would be useful in sci proper?
Or some better version of it
https://github.com/sicmutils/sicmutils/blob/master/src/sicmutils/env/sci.cljc#L27 starting here
@sritchie09 The pattern lib looks interesting, but some examples would help me better understand it, perhaps a nextjournal book even
@sritchie09 I have similar code here to copy an entire namespace: https://github.com/babashka/babashka/blob/ad93155d4f67bc7db4d8657aa75466682bc4a009/feature-rewrite-clj/babashka/impl/rewrite_clj.clj#L37 but I wonder if this works in CLJS or not
In Clojure at least, I'm able to also copy macros over
I also thought we could include a function like this, but maybe this can be in the documentation first. Note that your version does not create sci vars, but just maps a symbol to the value in the original Clojure var, so you don't get docstrings etc, that may also be a trade-off, depending on what environment you are creating with sci
I definitely want to create sci vars… that is a bug that I’ll need to fix
@borkdude here are some nice examples of rules… this namespace gets progressively messier as you go down, since I’m working my way through a cleanup from top to bottom 🙂 https://github.com/sicmutils/sicmutils/blob/40342b1c1b06e2a41ab2cf4294219492c1fc4233/src/sicmutils/simplify/rules.cljc#L189
(defn constant-elimination
"Takes an operator symbol `op` and an identity element `constant` and returns a
rule that eliminates instances of `constant` inside binary forms like
clojure
(<op> l r)
"
[op constant]
(ruleset
(~op ~constant ?x) => (~op ?x)
(~op ?x ~constant) => (~op ?x)))
here’s an example of a simple one… this will turn (+ 0 x) into (+ x)
, for example, Wrapping it in rule-simplifier
will cause it to do a depth first search of any data structure you pass, applying the pattern to any subexpression
that’s a tiny one, but there are lots and lots of these that build into a super powerful big simplifier
very cool!