This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-21
Channels
- # announcements (5)
- # babashka (9)
- # beginners (84)
- # calva (47)
- # clara (3)
- # clj-kondo (2)
- # clojars (8)
- # clojure-australia (3)
- # clojure-europe (3)
- # clojure-spec (1)
- # clojurescript (5)
- # conjure (6)
- # cursive (7)
- # datahike (3)
- # events (2)
- # helix (1)
- # lsp (217)
- # luminus (4)
- # malli (18)
- # meander (23)
- # membrane (12)
- # off-topic (26)
- # pathom (12)
- # reagent (44)
- # releases (1)
- # rewrite-clj (2)
- # shadow-cljs (19)
- # sql (17)
- # xtdb (6)
added more info on function schema explain:
(def MyFunctionSchema
(m/schema
[:function
[:=> [:cat :int] :int]
[:=> [:cat :int :int [:* :int]] :int]]
{::m/function-checker mg/function-checker}))
(m/explain
MyFunctionSchema
(fn
([x] x)
([x y & zs] (apply max x y zs))))
; => nil
(m/explain
MyFunctionSchema
(fn
([x] x)
([x y & zs] (str (apply max x y zs)))))
;{:schema [:function
; [:=> [:cat :int] :int]
; [:=> [:cat :int :int [:* :int]] :int]],
; :value #object[],
; :errors (#Error{:path [],
; :in [],
; :schema [:function
; [:=> [:cat :int] :int]
; [:=> [:cat :int :int [:* :int]] :int]],
; :value #object[],
; :check ({:total-nodes-visited 2,
; :depth 1,
; :pass? false,
; :result false,
; :result-data nil,
; :time-shrinking-ms 0,
; :smallest [(0 0)],
; :malli.generator/explain-output {:schema :int,
; :value "0",
; :errors (#Error{:path []
; :in []
; :schema :int
; :value "0"})}})})}
really happy how good the function schemas are now, but still - it’s just elegant (and slow) way to verify things at runtime, e.g. not a type system.
the sequence schemas are at least an order of magnitude faster than spec in initial tests. Full function verification uses test.check, I think that dominates, and quess they are about the same.
but, having arity info available for fn
s at runtime (in clojure.core) would help to see that fns are correct on arity, without testing it and getting arityexceptions - costs a lot.
I guess it could be done using a clj-kondo hook? with defaults, the test.check runs 19ms for a function on my machine. that’s 500 funcs per sec (on 1 core?). errors are faster, the given example fails fast on invalid return, under 1ms.
I mean: > but, having arity info available for fns at runtime (in clojure.core) would help to see that fns are correct on arity, without testing it and getting arityexceptions - costs a lot. You could use clj-kondo to find the correct arities perhaps
Btw, this sounds interesting, but I haven't heard anything about it yet: https://www.fulcrologic.com/copilot