This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-23
Channels
- # announcements (5)
- # aws (4)
- # babashka (141)
- # beginners (139)
- # calva (35)
- # cider (5)
- # clj-kondo (27)
- # cljsrn (20)
- # clojure (37)
- # clojure-czech (5)
- # clojure-dev (26)
- # clojure-europe (11)
- # clojure-germany (1)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-spec (17)
- # clojure-uk (16)
- # clojurescript (2)
- # conjure (1)
- # cursive (6)
- # datomic (20)
- # defnpodcast (1)
- # emacs (15)
- # fulcro (26)
- # honeysql (2)
- # instaparse (3)
- # jackdaw (4)
- # jobs (2)
- # lsp (70)
- # luminus (2)
- # meander (16)
- # missionary (2)
- # other-languages (151)
- # pathom (6)
- # portkey (13)
- # re-frame (13)
- # reagent (2)
- # reitit (43)
- # releases (1)
- # remote-jobs (1)
- # reveal (5)
- # rum (2)
- # sci (15)
- # shadow-cljs (37)
- # spacemacs (4)
- # tools-deps (8)
- # vim (20)
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
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