This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-11-18
Channels
- # architecture (33)
- # asami (1)
- # aws (1)
- # babashka (19)
- # beginners (48)
- # bristol-clojurians (1)
- # calva (5)
- # cider (12)
- # cljdoc (15)
- # cljsrn (7)
- # clojure (151)
- # clojure-europe (19)
- # clojure-losangeles (1)
- # clojure-nl (2)
- # clojure-provo (4)
- # clojure-spec (9)
- # clojure-uk (21)
- # clojuredesign-podcast (28)
- # clojurescript (33)
- # core-typed (1)
- # cryogen (2)
- # css (6)
- # cursive (10)
- # data-science (1)
- # datomic (20)
- # events (3)
- # expound (72)
- # figwheel-main (5)
- # fulcro (43)
- # graalvm (6)
- # helix (1)
- # kaocha (13)
- # leiningen (2)
- # malli (1)
- # meander (93)
- # membrane (4)
- # off-topic (17)
- # pathom (6)
- # portland-or (5)
- # re-frame (25)
- # reagent (6)
- # reitit (7)
- # reveal (30)
- # shadow-cljs (25)
- # vim (2)
@rfhayashi @borkdude Lemme know if this works with babashka @mark340 The record problem has been fixed.
@noprompt Is it necessary that the FAIL sentinel is seqable? https://github.com/noprompt/meander/blob/f4b1a90c75a8428e77f59feb0e152216e0460a82/src/meander/match/runtime/epsilon.cljc#L20
Ok, if not, could make it just an Object
(identical? (js/Object.) (js/Object.)) ;;=> false
I could support this (reify of ISeqable) in bb but if I don't have to .. :)(reify ISeqable ...)
doesn't work. Since FAIL
is just some unique value to indicate failure, I wondered if this was really necessary to be a seqable. You could also just make it ::whatever
or Object
reify does work for some cases, but I have to make explicit support for it on a class by class basis :/
@noprompt Hmm, did you mean (reify)
as in without args? That works:
$ bb -e '(identical? (reify) (reify))'
false
Hehe. So what I should have said is “if removing the seqable stuff works then just leave it as (def FAIL (reify))
.”
The seqable stuff is not removable it appears, however, I’m happy to support a :bb
clause.
This works as well:
user=> (identical? (String. "FAIL") (String. "FAIL"))
false
cljs.user=> (identical? (js/String. "FAIL") (js/String. "FAIL"))
false
The string object is unique and seqable.oh wait:
(seq "")
;;=> nil
that works too.
So:
cljs.user=> (identical? (js/String. "") (js/String. ""))
false
fits the bill in all cases.user=> (identical? (list) (list))
true
user=> (identical? (with-meta (list) {}) (list))
false
user=> (identical? (with-meta (list) {}) (with-meta (list) {}))
false
I think there are metadata values with metadata. E.g. when you datafy something, the original value is stored as metadata
I'm now running into another Seqable reference:
user=> (require '[meander.epsilon] :reload)
Could not resolve symbol: clojure.lang.Seqable [at /Users/borkdude/.gitlibs/libs/meander/epsilon/7ed07ce8766aa5fbf7d457bdeffe39e2e1323f73/src/meander/match/ir/epsilon.cljc:851:31]
Maybe I'll just have to bite the bullet and add it to bbThis isn't exactly the same though:
#'clojure.core/seqable? clojure.lang.Seqable
E.g. strings are seqable, but they are not clojure.lang.Seqable
set? checks for IPersistentHashSet but you map it to PersistentHashSetI support clojure.lang.IPersistentSet
already in bb. I'll add support for checking Seqable
as well
We should probably tag @U5K8NTHEZ on this bit too. 🙂
@U5K8NTHEZ No pressure. I’m hacking away at them as @borkdude brings stuff up. I just wanted to tag you on the thread.
The next thing I'm running into:
user=> (require '[meander.epsilon] :reload)
Could not resolve symbol: clojure.lang.RT/iter [at /Users/borkdude/.gitlibs/libs/meander/epsilon/7ed07ce8766aa5fbf7d457bdeffe39e2e1323f73/src/meander/substitute/runtime/epsilon.cljc:11:12]
Don't know what the normal Clojure function is for this, but you might want to add a :bb branch for this. Note that :bb branches have to go before :clj branches, else bb will take the :clj branch :)Basically the goal is to make a java.lang.Iterator
and this was the easiest way to do that without porting the RT code.
I think that would be useful regardless of babashka, as to not rely on Clojure internals too much
Basically wrote
(if (instance? java.lang.Iterable coll)
(.iterator ^java.lang.Iterable coll)
(.iterator (seq coll)))
Feedback:
(set! *warn-on-reflection* true)
(defn iter [coll]
(if (instance? java.lang.Iterable coll)
(.iterator ^java.lang.Iterable coll)
(.iterator ^java.lang.Iterable (seq coll))))
(prn (iter []))
(prn (iter "x")) ;; needs type hint on seq
(prn (iter nil)) ;; needs fixing
You still need a type hint here: https://github.com/noprompt/meander/commit/6f7b8265e5102ae98eb304719b884a73aef53fe3#diff-cdb266462b83e64b48c052f2f26fca6ea027e9663cce3ff64b08fc81b840e69bR16
That's easy to fix. Let me get back to you after I finish another (unrelated) refactor
You can bang on that branch if you want. I’ve gotta take my hands off of it for a bit.
This is a better way to write it for bb:
(defn iter [coll]
(if (instance? java.lang.Iterable coll)
(.iterator ^java.lang.Iterable coll)
(.iterator ^java.lang.Iterable (seq coll))))
since it actually uses the type hintI now pushed a commit to bb master where this should work:
(defn iter [coll]
(if (instance? java.lang.Iterable coll)
(.iterator ^java.lang.Iterable coll)
(let [s (or (seq coll) [])]
(.iterator ^java.lang.Iterable s))))
Also added a unit test for it:
(= [1 2 3] (iterator-seq (iter [1 2 3])))
iter
is fixed now on babashka master. Note that you can download binaries from #babashka_circleci_builds or simply from the builds on Github, if you want to try the binary version.
The next issue I'll just mention on Github
The next issue is the 2 arg version of resolve. I'll have to fix that in sci (the interpreter backing babashka).
I fixed a couple of issues. The latest issue I'm running into: https://github.com/noprompt/meander/issues/153
Also made this comment: https://github.com/noprompt/meander/issues/153#issuecomment-730255519
I have this function in plain Clojure. Out of curiosity, what would be the meander equivalent? I feel it should be straight forward, but I have not found a concise solution using meander.
(defn replace-value [data]
(clojure.walk/prewalk
#(if (:a %)
(assoc % :a (:b %))
%) data))
You could use the strategy namespace combining top-down
and rewrite
.
(m*/top-down
(m*/rewrite
{:a (m/or false nil), :b ?b & ?m}
{:a ?b & ?m}))
but, honestly, what you have is probably fine.If you need it to be quicker, you’ll need to ditch both prewalk
and avoid top-down
. These traversals indiscriminately hit everything and 99% of that’s a waste.
@rfhayashi We’re (@borkdude and I) have been working back and forth on supporting bb
. There’s an issue and PR in the works.