sci

https://github.com/babashka/SCI - also see #babashka and #nbb
Sam Ritchie 2021-04-23T14:43:02.010800Z

https://mobile.twitter.com/sritchie/status/1385354524034887681

1🎉
Sam Ritchie 2021-04-23T14:43:15.011400Z

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

Sam Ritchie 2021-04-23T14:44:14.012900Z

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 Ritchie 2021-04-23T14:44:21.013200Z

Or some better version of it

Sam Ritchie 2021-04-23T14:44:46.013500Z

https://github.com/sicmutils/sicmutils/blob/master/src/sicmutils/env/sci.cljc#L27 starting here

borkdude 2021-04-23T18:30:38.014400Z

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

borkdude 2021-04-23T18:31:38.015100Z

@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

borkdude 2021-04-23T18:32:48.015600Z

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

borkdude 2021-04-23T18:34:59.017Z

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 Ritchie 2021-04-23T18:56:41.017400Z

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

Sam Ritchie 2021-04-23T18:57:53.018100Z

@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 Ritchie 2021-04-23T18:58:33.019Z

(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) =&gt; (~op ?x)
   (~op ?x ~constant) =&gt; (~op ?x)))

Sam Ritchie 2021-04-23T18:59:12.019900Z

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 Ritchie 2021-04-23T18:59:30.020400Z

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

borkdude 2021-04-23T20:17:27.020600Z

very cool!