Fork me on GitHub

@borkdude @mrevelle I've run into problems using s/valid? in production. If my specs use fspecs, 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/replace #"@.*" "")
    (str/replace #"_" "-")
    (str/split #"\$")
    (->> (apply symbol)))
; user/kikka

Alex Miller (Clojure team)12:03:12

You can demunge the class name

Alex Miller (Clojure team)12:03:36

But won’t always work

Alex Miller (Clojure team)12:03:16

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?

Alex Miller (Clojure team)13:03:45

function objects are just function objects - the fact that a particular var is referring to them is in some ways incidental.

Alex Miller (Clojure team)13:03:25

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)

Alex Miller (Clojure team)13:03:57

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

Alex Miller (Clojure team)13:03:34

there are a lot of good reasons to fight this kind of introspection and instead try to drive from symbols or vars

Alex Miller (Clojure team)13:03:53

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 style of keywords or the :invoice/total style?

Alex Miller (Clojure team)14:03:33

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).

Alex Miller (Clojure team)14:03:52

if you are writing a private app, then you should make qualifiers "sufficiently unique"

Alex Miller (Clojure team)14:03:26

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 😕

Alex Miller (Clojure team)19:03:27

I'm not sure I've ever built it

Alex Miller (Clojure team)19:03:46

the doc builder works off of a release and we haven't released a version of it yet

Alex Miller (Clojure team)19:03:16

in other words, the link is right, the target is absent :)

Alex Miller (Clojure team)19:03:29

I can try to build it but I'm probably not going to have time today

Alex Miller (Clojure team)19:03:01

Posted a writeup on the (still in work) schema and select in spec 2:

sheepy 28
❤️ 64
bellissimo 4

thanks a lot 🙂


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])
user=> (s/def ::name string?)
user=> (s/def ::street string?)
user=> (s/def ::city string?)
user=> (s/def ::zip string?)
user=> (s/def ::addr (s/schema [::street ::city ::zip]))
user=> (s/def ::user (s/schema [::name ::addr]))
user=> (s/def ::data (s/select ::user [::name {::addr [::zip]}]))
user=> (s/valid? ::data {::name "Sean"}) ; ::addr is optional
user=> (s/valid? ::data {::name "Sean" ::addr {}}) : but when provided it must contain ::zip
user=> (s/valid? ::data {::name "Sean" ::addr {::zip "94546"}})

👍 8
Alex Miller (Clojure team)03:04:27

@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.

👍 4