This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-16
Channels
- # autochrome-github (17)
- # aws (6)
- # babashka (19)
- # beginners (42)
- # bristol-clojurians (1)
- # calva (1)
- # cider (7)
- # clara (1)
- # clj-kondo (6)
- # cljdoc (17)
- # cljs-dev (5)
- # clojars (23)
- # clojure (93)
- # clojure-europe (20)
- # clojure-italy (28)
- # clojure-nl (13)
- # clojure-sanfrancisco (1)
- # clojure-uk (50)
- # clojuredesign-podcast (5)
- # clojurescript (90)
- # core-async (8)
- # datomic (23)
- # duct (3)
- # emacs (10)
- # figwheel-main (1)
- # fulcro (1)
- # malli (1)
- # meander (22)
- # off-topic (12)
- # pathom (57)
- # reitit (4)
- # remote-jobs (5)
- # shadow-cljs (5)
- # sql (8)
- # tools-deps (3)
(m/match 1 ^String ?s ?s)
^^ I’d like this to not match… i.e. I’d like Meander to treat type hints as special predicates… thoughts?The motivation being that I have a lot of (m/pred string? ?s)
and I’d argue that it obscures the structure of what I’m matching, where as ^String
doesn’t change the structure.
^String
being the way to type hint in Clojure makes it somewhat intuitive that if I type hint a pattern, I’d like it to conform to the type.
Why meta over just a string operator? (string ?d)
FWIW I get a little confused whenever I see (anything)
;; is that going to match a list or a thing? Well, it depends on what anything
is naturally 🙂 Conversely I like when I can write []
or {}
and know that it will only match a vector or map. So type hints feel like a more familiar way to say this thing is an X
… (m/pred string? ?s)
is in my view not any worse than (string ?s)
so given those options, I’d probably stick with m/pred
just because it’s more obvious when reading.
(defn chain [x [c & chains]]
(if c
(recur (list '. x c) chains)
x))
(defn chain [xs]
(m/rewrite xs
[?x ()] ?x
[?x ((!chain ...) & ?more-chains)]
(m/cata [('. ?x . !chain ...) ?more-chains])))
(chain ['(new List) '((push_back 1)
(push_back 2)
(push_back 3))])
1. It seems wierd to me that I can use the meander
version of rewrite with m/cata
but not the strategy
version. There is probably a good reason though.
2. m/cata
seems like the dual of m/with
3. Is the meander version better? I think so but am having trouble justifying it..
I can't really speak to why strategies doesn't have cata. I will say that we are hoping with zeta that strategies will not need to be separate and will not be function combinator based. Not 100% sure what that looks like yet though.
Strategy rewrite could have cata. The only thing that doesn’t have cata is rewrites because the current state of the compiler on epsilon would require some heavy rework to make of feasible.
roger roger; was just curious, not requesting 🙂 thanks for clarifying.
(m/rewrite [1 ["a" 2] "b" 3 "c"]
(m/$ ?replace (m/pred string? !s))
~(?replace (map keyword !s)))
^^ Doesn’t work (perhaps unsurprisingly) => [1 [(:a) 2] "b" 3 "c"]
What I’m trying to do is convert all the strings to keywords… Well what I’m really trying to do is more complicated than that but this is a minimal example 🙂
TLDR it would be awesome if $
could substitute transformations (not just values)Also I wish it replaced all occurences 🙂
what does $*
do ???? o_O
I claim $*
is broken on epsilon
(m/rewrite [1 ["a" 2] "b" 3 "c"]
(m/$ ?replace (m/pred string? ?s))
(m/cata ~(?replace (keyword ?s)))
?x ?x)
^^ This works but is kinda gross because it will restart the tree walk over from scratch each time..(me/rewrite [1 ["a" 2] "b" 3 "c"]
(me/$ ?replace (me/pred string? ?s))
(me/cata (me/$ ?replace (me/keyword nil ?s)))
?x ?x)
This is something I want to address in the near feature with a tree
thing for describing these kinds of things.
(def p
(s/top-down
(s/match
(m/pred string? ?s) (keyword ?s)
?x ?x)))
(p [1 ["a" 2] "b" 3 "c"])
=> [1 [:a 2] :b 3 :c]