This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-20
Channels
- # adventofcode (17)
- # announcements (1)
- # aws (1)
- # beginners (102)
- # calva (27)
- # cider (16)
- # clj-commons (34)
- # clj-kondo (33)
- # cljs-dev (5)
- # cljsrn (4)
- # clojure (124)
- # clojure-europe (17)
- # clojure-nl (8)
- # clojure-spec (13)
- # clojure-uk (6)
- # clojurescript (68)
- # datahike (21)
- # datomic (23)
- # emacs (3)
- # fulcro (30)
- # introduce-yourself (6)
- # jobs-discuss (6)
- # lsp (31)
- # nextjournal (3)
- # off-topic (1)
- # other-languages (45)
- # portal (4)
- # re-frame (8)
- # releases (4)
- # shadow-cljs (39)
- # specter (6)
- # tools-build (18)
- # tools-deps (11)
hello, is there a place that explains how to properly implement the s/Spec
protocol? I'm not sure about some of the methods, also, is there a place that explains the :path
, :via
and :in
parts of the spec problems? (I see in the spec docs it talks about but doesn't mention exact those keys)
No, we don't really consider that public api
But if you have a question I'll try to answer it :)
mostly about the :path
, :via
and :in
, what is expect on each and what makes it different from one another?
there is some info at https://clojure.org/guides/spec#_explain
although those are words in the error message that map to the keys:
• :path
- vector of keyword tag "path" segments (usually from :or, :cat, :alt, etc)
• :via
- vector of spec names from the root
• :in
- vector of data values from root to failing value (will be omitted if it's the root value)
there's an implicit tree being recursively walked here. the nodes are specs (name = :via element). Each edge has a name (:path element) and the value to validate (:in element)
in some cases, some of those are synthetic, created by the spec
the examples I'm seeing are mostly related to s/keys
, where I see things like this:
(s/def ::a string?)
(s/explain-data (s/keys :req [::a]) {::a 1})
{:clojure.spec.alpha/problems ({:path [:com.piposaude.model.bulk-insert-test/a],
:pred clojure.core/string?,
:val 1,
:via [:com.piposaude.model.bulk-insert-test/a],
:in [:com.piposaude.model.bulk-insert-test/a]}),
:clojure.spec.alpha/spec #object[clojure.spec.alpha$map_spec_impl$reify__1998
0xabd19ae
"clojure.spec.alpha$map_spec_impl$reify__1998@abd19ae"],
:clojure.spec.alpha/value {:com.piposaude.model.bulk-insert-test/a 1}}
in this case all :path
, :via
and :in
are the same value
but from what I got to you, is like:
:in
- path from root
:path
- local path
:via
- specs in the process
is that a fair simplification of them?
and do you have examples that can clear up the distinction?
they are all "paths", but :in
is data, :path
is tags, and :via
is specs