Fork me on GitHub
#sci
<
2021-04-23
>
Sam Ritchie14:04:15

Merged a change last night that makes all of this compatible with SCI, macros and all!

Sam Ritchie14:04:14

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?

Sam Ritchie14:04:21

Or some better version of it

borkdude18:04:38

@sritchie09 The pattern lib looks interesting, but some examples would help me better understand it, perhaps a nextjournal book even

borkdude18:04:48

In Clojure at least, I'm able to also copy macros over

borkdude18:04:59

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

Sam Ritchie18:04:41

I definitely want to create sci vars… that is a bug that I’ll need to fix

Sam Ritchie18:04:53

@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

Sam Ritchie18:04:33

(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)))

Sam Ritchie18:04:12

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

Sam Ritchie18:04:30

that’s a tiny one, but there are lots and lots of these that build into a super powerful big simplifier