This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-25
Channels
- # anglican (2)
- # babashka (53)
- # beginners (99)
- # brompton (1)
- # calva (28)
- # circleci (43)
- # clj-commons (4)
- # clj-kondo (176)
- # cljsrn (22)
- # clojars (7)
- # clojure (175)
- # clojure-australia (2)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-uk (5)
- # clojurescript (195)
- # cursive (18)
- # datomic (13)
- # emacs (2)
- # farolero (9)
- # find-my-lib (6)
- # fulcro (8)
- # graalvm (12)
- # gratitude (5)
- # helix (11)
- # improve-getting-started (36)
- # introduce-yourself (3)
- # jackdaw (21)
- # jobs (2)
- # joker (2)
- # malli (65)
- # meander (24)
- # nbb (2)
- # off-topic (4)
- # pathom (2)
- # polylith (17)
- # portal (5)
- # react (3)
- # reagent (22)
- # releases (1)
- # ring (4)
- # shadow-cljs (79)
- # show-and-tell (2)
- # testing (5)
- # tools-deps (9)
- # xtdb (12)
@zikajk looks weird. md/start!
btw calls the clj-kondo too, so just md/start!
and you are done
@ikitommi I will try, I experienced this after long running repl session so there could be a lot of reasons. After restarting - everything is working great.
works here:
(def valid?
(m/validator
[:map
[:export? boolean?]
[:import? boolean?]
[:gcs-name string?]
[:extra string?]]))
(valid?
{:export? true
:import? true
:gcs-name "kikka"
:extra "foo"})
; => true
I'm trying to use reitit-malli coercion with malli 0.6.1. When evaling [reitit.coercion.malli :as rss] I'm getting
------ WARNING - :fn-arity -----------------------------------------------------
Resource: <eval>:2007:43
Wrong number of args (3) passed to malli.core/-fail!
--------------------------------------------------------------------------------
Can someone reproduce?@karol.wojcik that’s a bug, the 3-arity was removed. please write an issue, need to fix reitit (or revert the change if it’s really needed)
Thank you @ikitommi for blazing fast response. I will write an issue! No worries I can wait 🙂
Everyone: malli master has massive performance improvements related to Schema creation and transformation performance. If you are using malli especially with cljs, you might see order of magnitude improvements to startup-times. Please try and report both gains and bugs. Big thanks for @ben.sless for much of the hard work.
(def ?schema
[:map
[:x boolean?]
[:y {:optional true} int?]
[:z [:map
[:x boolean?]
[:y {:optional true} int?]]]])
;; 44µs => 8.5µs (5x)
(def schema (m/schema ?schema))
;; 26µs => 1.3µs (20x)
(m/walk schema (m/schema-walker identity))
;; 51µs => 6.5µs (8x)
(mu/closed-schema schema)
… there is still a lot of room for improvements, but would like to release these soon. Issue tracking, alternative ways to build large schema systems described and comment welcome on https://github.com/metosin/malli/issues/513.@ikitommi Here's a riddle I can't find a good answer to, how come this is significantly faster than a PersistentHashMap backed registry
(defn fast-registry
[m]
(let [pred (comp keyword? key)
im (doto (new IdentityHashMap 1000) (.putAll (into {} (filter pred) m)))
-m (doto (new HashMap 1000 0.25) (.putAll (into {} (remove pred) m)))]
(reify mr/Registry
(-schema [_ k]
(let [^Map m (if (instance? Keyword k) im (if (instance? Var k) im -m))]
(.get ^Map m k)))
(-schemas [_] m))))
By about 35 ns for keyword lookup
compare
(cc/quick-bench (m/schema :int {:registry r}))
(cc/quick-bench (m/schema :int))
But the registry lookup isn't that much faster, only ~7 ns
(cc/quick-bench (mr/-schema r :int))
(cc/quick-bench (mr/-schema m/default-registry :int))
🤷 micro benchmarks are hard. I would ask JMH how they really differ. Just swapping order of the tests, you might get different results. Also, more code, JIT behaves differently.
Super quick googling: https://www.oracle.com/technical-resources/articles/java/architect-benchmarking.html
The malli readme might be a good candidate for https://github.com/lread/test-doc-blocks. I could take a whirl at it if there is any interest.
@ikitommi I won’t proceed unless you indicate an interest. Might be your cup of tea and might not! Happy to do the PR for you to evaluate then decide if you like - or not.
I’m getting an fn-arity
warning when requiring malli.core
in a cljs repl:
; eval (current-form): (require 'malli.core)
; (err) ------ WARNING - :fn-arity -----------------------------------------------------
; (err) Resource: <eval>:2007:43
; (err) Wrong number of args (3) passed to malli.core/-fail!
; (err) --------------------------------------------------------------------------------
You welcome Martin! 🙂
@ikitommi do you think it’s worth documenting this in the changelog for 0.7?
PR welcome @U050TNB9F, but there is a a already this line: > * fixed arity error in `m/function-schema`
Hi, I am getting
Expected: regular expression, received: string.
in clj-kondo lsp / Emacs combo with instrumentation
for :
(def gcs-uri "
(gcs/get-blob-moddate gcs-uri)
and these are my schemas:
(m/=> get-blob-moddate [:=>
[:cat Gcs-uri]
[:or
[:fn #(= (type %) org.joda.time.DateTime)]
nil?]])
(def Gcs-uri
[:re #"gs:\/\/.*"])
Is it possible to instrument function via metadata in Clojurescript?
someone needs to port the tooling to support cljs. I suck at macro+interop, so not going to do that any time soon. help most welcome.
I will take a look into it when I have some time 🙂
Am having a great time experimenting with malli to validate cljdoc’s cljdoc.edn
. The docs and demos are great in helping me to understand how things work. Thank you for all that effort. As a newb, I was wondering about the following:
1. The https://malli.io/?value=%5B1%20%5B2%20%5B3%20%5B4%20nil%5D%5D%5D%5D&schema=%5B%3Aschema%0A%20%7B%3Aregistry%20%7B%22ConsCell%22%20%5B%3Amaybe%20%5B%3Atuple%20%3Aint%20%5B%3Aref%20%22ConsCell%22%5D%5D%5D%7D%7D%0A%20%22ConsCell%22%5D uses [:ref "ConsCell"]
but the https://malli.io/?value=%5B%3Adiv%20%7B%3Aclass%20%5B%3Afoo%20%3Abar%5D%7D%20%5B%3Ap%20%22Hello%2C%20world%20of%20data%22%5D%5D&schema=%5B%3Aschema%0A%20%7B%3Aregistry%20%7B%22hiccup%22%20%5B%3Aorn%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Anode%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Acatn%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Aname%20keyword%3F%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Aprops%20%5B%3A%3F%20%5B%3Amap-of%20keyword%3F%20any%3F%5D%5D%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Achildren%20%5B%3A*%20%5B%3Aschema%20%5B%3Aref%20%22hiccup%22%5D%5D%5D%5D%5D%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Aprimitive%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Aorn%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Anil%20nil%3F%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Aboolean%20boolean%3F%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Anumber%20number%3F%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%3Atext%20string%3F%5D%5D%5D%5D%7D%7D%0A%20%22hiccup%22%5D uses [:schema [:ref "hiccup"]]
. Are [:ref x]
and [:schema [:ref x]]
equivalent?
2. I was unfamiliar with :maybe
and was not confident what it did. From the examples it seems that [:maybe x]
validates for x
or nil
?
3. I was unfamiliar with :tuple
and now think I understand it just fine. But maybe a sentence contrasting it with :vector
(if that makes sense) would be helpful to newcomers.
4. Very subjective, but I would put the motivation section before examples. As a newbie, this kind of info would be helpful to me up front.
If updates to docs and demos for any the above would be helpful I am happy to make those wee changes.
Also once I’ve finalized my cljdoc.edn validation I would be happy to add that as a, perhaps familiar, example to docs, demos or both.
I think schema of ref cannot be derefed. This lets you write things like recursive sequence schemas
Thanks @ben.sless! - Are you suggesting maybe the hiccup demo might be a bit off?
Can't say without giving it a deeper look. I bumped by head against it separately trying to port the datalog BNF to malli
Schema schemas create a "hard" boundary when schemas are compiled and you don't get deref-ed recursively ad inifinitum
It's a good idea to do so anyway, it's a small change you can do now, the guide will take some time
When working on your datalog BNF were you able to generate
and sample
without sporadic StackOverflowError exceptions?
here you go https://github.com/bsless/mallilog/blob/master/src/mallilog/impl/schema.clj
Yeah! So maybe that tells us something about my first question(?). You don’t seem to use :ref
without it wrapped in :schema
.
That's because my schemas are mostly recursive but I probably don't need to do it everywhere
I can try by process of elimination to knock it out and see what's up but it's pedantic and didn't really feel like fighting with it
Took a stab at https://github.com/metosin/malli/pull/537.
Hiya mallians! I’m making some good progress with my cljdoc.edn malli schema. I am, though, getting some StackOverflowError exceptions when generating samples. This might be normal, I’m new, what do I know? Rather than share and diagnose my cljdoc.edn schema, it might be more fruitful to work from the familiar. The Hiccup schema from the malli README seems to have-ish the pattern of recursion I want for cljdoc.edn. If I take the Hiccup schema unchanged from the README I do not seem to suffer StackOverflowError exceptions.
(def Hiccup
[:schema {:registry {"hiccup" [:orn
[:node [:catn
[:name keyword?]
[:props [:? [:map-of keyword? any?]]]
[:children [:* [:schema [:ref "hiccup"]]]]]]
[:primitive [:orn
[:nil nil?]
[:boolean boolean?]
[:number number?]
[:text string?]]]]}}
"hiccup"])
(mg/sample Hiccup)
But if I yank out some stuff and make the schema look a little more like my cljdoc.edn schema usage, I can easily trigger StackOverflowError exceptions by re-evaluating (mg/sample Hiccup2)
a handful of times:
(def Hiccup2
[:schema {:registry {"hiccup" [:catn
[:name keyword?]
[:props [:? [:map-of keyword? any?]]]
[:children [:* [:schema [:ref "hiccup"]]]]]}}
"hiccup"])
(mg/sample Hiccup2)
I am likely quite naive in my understanding here. I’m guessing if I somehow limited the maximum tree depth (which would be reasonable thing to do anyway for my use case) that would help but I am not sure how to express that.
I am using malli 0.6.1.@UE21H2HHD Without saying i’m an authority here, it seems that your schema doesn’t have a stop condition? So endless recursion? Whereas the hiccup one has an alternative which stops the recursion. Makes sense?
The only stop condition you have is when there are 0 children for one node
Ah right… thanks @U0FT7SRLP! That makes perfect sense. For the generator, the :orn
is probably a 50/50 coin toss for termination whereas hitting 0 children for termination is much less likely.
Yeah and then there is the branching of the children 😅 1 child still ok, but 2 or more and there you go
So constructing a schema for validation is one thing and then adapting it to to support sensible generation is another consideration.
With clojure.spec https://clojure.org/guides/spec#_custom_generators, so I’m guessing this would make sense for Malli too. (I haven’t done it yet with Malli)