This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-05-23
Channels
- # announcements (12)
- # beginners (225)
- # calva (7)
- # cider (45)
- # clj-kondo (1)
- # cljdoc (1)
- # cljsrn (3)
- # clojure (112)
- # clojure-dev (45)
- # clojure-europe (6)
- # clojure-finland (2)
- # clojure-india (1)
- # clojure-nl (27)
- # clojure-spec (37)
- # clojure-uk (171)
- # clojurescript (39)
- # core-async (9)
- # cursive (22)
- # datascript (8)
- # datomic (50)
- # emacs (12)
- # figwheel-main (17)
- # fulcro (42)
- # garden (2)
- # hoplon (27)
- # jobs (4)
- # kaocha (8)
- # klipse (2)
- # luminus (2)
- # off-topic (9)
- # perun (33)
- # planck (2)
- # re-frame (9)
- # reagent (48)
- # reitit (5)
- # remote-jobs (1)
- # rum (2)
- # shadow-cljs (23)
- # slack-help (3)
- # spacemacs (18)
- # sql (7)
- # tools-deps (24)
- # unrepl (9)
- # vim (30)
Not sure but perhaps https://clojure.github.io/spec.alpha/clojure.spec.test.alpha-api.html#clojure.spec.test.alpha/enumerate-namespace could help?
(st/instrument (st/enumerate-namespace 'my.core))
Enum. enumerates all vars but instrument seems to be happy with that and presumabely skips those that are not spec-instrumentable.
am i missing something regarding s/union
and s/select
? i’m trying to do something like this:
(require '[clojure.spec-alpha2 :as s])
(s/def ::n number?)
(s/def ::o odd?)
(s/def ::schema1 (s/schema [::n]))
(s/def ::union1 (s/union ::schema1 [::o]))
(s/select ::union1 [*]) ;; => IllegalArgumentException
(s/select (s/union ::schema1 [::o]) [*]) ;; => IllegalArgumentException
probably broken atm. top-level union is probably going to go away anyways
I'll take a look when I next get a chance
could the s/def
fail-fast on totally bogus spec-forms? what would be a spec for the spec-form
arg in s/def
?
(s/def ::a 1)
;; :user/a
(s/valid? ::a 1)
;; Syntax error (ClassCastException)
;; java.lang.Long cannot be cast to clojure.lang.IFn
it could check some things better, for sure
what's valid is changing between spec 1 and 2
in spec 2 the valid symbolic forms are keywords, sets, symbols, and lists/sequences which are spec forms where a known spec op is in op position (ops are an extension point via multimethod)
we may add another datafied/map form, still tbd
notably, function objects are not allowed (different than spec 1)
hey all, does anyone know why can’t I do something like this with spec?
(s/def ::profile (s/keys :req-un {::id int?
::name string?
::photos (s/* (s/keys :req-un {::type int?}))}))
you mean, inline a spec in s/keys?
by design, spec is trying to enable a shared global registry of attribute specs
the attribute spec is considered to be more important than containers of those attributes
as such, we require you to strongly associate a spec with an attribute name
spec 2 will have more support for inlining attribute spec defs for unqualified keys (common with json interop)
I see. Being new to spec I find that not being able to inline specs makes it harder for me to reason about them but I suppose that might change once I get more familiar with it, and one I learn about the best practices on creating specs (any suggested links?).
btw, thanks for the response @alexmiller
have you read the guide? https://clojure.org/guides/spec ?
or the rationale? https://clojure.org/about/spec
curious if there is a significant expected runtime difference between computing s/select
s dynamically and def
ing them prior. e.g. if the following s/valid
calls were going to be called in a loop:
(require '[clojure.spec-alpha2 :as s])
(s/def ::schema1 (s/schema [...]))
(s/def ::select1 (s/select ::schema1 [...]))
(def select2 (s/select ::schema1 [...]))
(s/valid? ::select1 {...})
(s/valid? select2 {...})
(s/valid? (s/select ::schema1 [...]) {...})
you should expect that we have spent no time yet on perf aspects of select :)
in general though, the first two are reusing the same spec object, which means work can be done once at spec object creation time (optimization work is basically shifting as much work as possible into construction time here) whereas the last one would pay that cost every time
exactly—was about to say that i suppose i’d always def it, if it weren’t truly dynamic. was just tangentially curious about the perceived cost of the dynamism there
so in general, I would tend toward either using an object saved in var or from the registry (those are probably approx the same)
but also note that the tradeoff, as usual, is in not picking up changes to specs in the ... there
so you might make the opposite choice at the repl, if you're in development
generally, I am just working in a file, that has all the specs I'm working on in it, and I just reload the file, which registers and recompiles all of the specs, and I don't care
it is useful to have that mental model though