This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-29
Channels
- # announcements (9)
- # aws (1)
- # beginners (133)
- # boot (2)
- # calva (94)
- # cider (48)
- # cljdoc (7)
- # cljsrn (22)
- # clojure (128)
- # clojure-europe (22)
- # clojure-finland (7)
- # clojure-greece (6)
- # clojure-losangeles (3)
- # clojure-nl (81)
- # clojure-spec (30)
- # clojure-uk (60)
- # clojure-ukraine (1)
- # clojurescript (45)
- # core-async (26)
- # cursive (18)
- # datomic (12)
- # defnpodcast (1)
- # duct (4)
- # editors (4)
- # emacs (6)
- # fulcro (37)
- # graphql (4)
- # jobs (2)
- # jobs-rus (1)
- # juxt (7)
- # kaocha (2)
- # leiningen (1)
- # nrepl (22)
- # off-topic (2)
- # re-frame (16)
- # reagent (8)
- # reitit (22)
- # ring-swagger (5)
- # shadow-cljs (81)
- # tools-deps (4)
@borkdude @mrevelle I've run into problems using s/valid?
in production. If my specs use fspec
s, it will throw in prod because no test.check. We work around this by never passing a function to a function that uses s/valid?
but seems a bit dangerous. Would be nice to be able to disable fspec
generative checking in certain production.
Is there a way to extract the fdef
specs, given one has a function at hand? e.g. need to get the symbol out of the function to be able to look up for it’s spec. Functions are quite opaque in clojure (or I’m just doing it wrong)
something like this, but for real (and without eval
):
(defn kikka [])
(-> kikka
str
(str/replace #"@.*" "")
(str/replace #"_" "-")
(str/split #"\$")
(->> (apply symbol)))
; user/kikka
You can demunge
the class name
But won’t always work
In general, it’s better if you can start from a symbol than start from a function object
Thanks. In my case, I just don’t have the symbols available, just functions. Knowing the arity of the functions at runtime would be useful too to be able to fail fast in case of invalid arity of the (framework) functions (middleware, interceptors etc). Any change of getting the function symbol & arity queryable for runtime?
function objects are just function objects - the fact that a particular var is referring to them is in some ways incidental.
same for arity, although that one in particular is one that affects code evolution over time (it's common for arities to expand but still be backwards compatible)
I know these seem like obvious things to have on a function, but I think the implications are probably a lot more far reaching and subtle than you expect
there are a lot of good reasons to fight this kind of introspection and instead try to drive from symbols or vars
so, in short, no, not eagerly looking to make these changes
@kenny we don’t use fdef
because of this. And I agree, disabling the test generator req would help. I think it was mentioned as possibly coming in spec2
a bit of a philosophical question: I know spec uses qualified keywords, but do people normally go for the :com.my-company.invoice/total
style of keywords or the :invoice/total
style?
if you are writing a public library, then I think you endeavor to start your qualifier with something you control (by trademark, domain name, etc).
if you are writing a private app, then you should make qualifiers "sufficiently unique"
whether that means including company, department, product, whatever is relevant
@alexmiller thanks, that’s a balanced view which I think makes sense
I'm starting to regret using particularly unique keywords that include the company name and sub project as a prefix for an application. I'm considering adding aliases to human written edn because of it.
hey guys, does somebody knows what is the url of the api docs for spec-alpha2 ? The link seems to be broken in https://github.com/clojure/spec-alpha2 😕
I'm not sure I've ever built it
the doc builder works off of a release and we haven't released a version of it yet
in other words, the link is right, the target is absent :)
I can try to build it but I'm probably not going to have time today
Posted a writeup on the (still in work) schema and select in spec 2: https://github.com/clojure/spec-alpha2/wiki/Schema-and-select
I know what I'll be doing this weekend (while my wife's in China)... 🙂
Looking good, thanks Alex! Couple of thoughts/questions on that document:
- on first encounter, it seems confusing (and complecting 😉 ) to treat schemas sometimes as though they're specs (`s/def`, same registry) and sometimes not (can't be used for valid?
etc). Why not either a) let them act as specs (maybe a schema acts like (s/select my-schema)
, ie all optional, when treated as a spec?) or b) make them fully separate (separate registry, can't use s/def
to register them)?
- What do you mean by 'SPI'? 'Serial-parallel interface'? :thinking_face:
- In the "get-movie-times" example, is there a way to say that address is optional, but if present it must include zip? I know I've encountered use cases like that in practice.
Yes, omit address from the vector but still provide the map for the sub-select
user=> (require '[clojure.spec-alpha2 :as s])
nil
user=> (s/def ::name string?)
:user/name
user=> (s/def ::street string?)
:user/street
user=> (s/def ::city string?)
:user/city
user=> (s/def ::zip string?)
:user/zip
user=> (s/def ::addr (s/schema [::street ::city ::zip]))
:user/addr
user=> (s/def ::user (s/schema [::name ::addr]))
:user/user
user=> (s/def ::data (s/select ::user [::name {::addr [::zip]}]))
:user/data
user=> (s/valid? ::data {::name "Sean"}) ; ::addr is optional
true
user=> (s/valid? ::data {::name "Sean" ::addr {}}) : but when provided it must contain ::zip
false
user=> (s/valid? ::data {::name "Sean" ::addr {::zip "94546"}})
true
user=>
@U077BEWNQ - schemas as specs would be pretty useless since map specs are open (any map would validate) so we decided to make them different. There are some real subtle questions in the idea of wanting to have both for different purposes though and I haven't had a chance to talk through it with Rich yet. might change. - SPI = service provider interface, for those building new kinds of specs/schemas, vs API which is what consumers use. probably should have explained that more clearly.