clojure-spec

evocatus 2024-06-12T15:52:55.090479Z

Can I separate function definition (with defn) and schema (with fdef) into different namespaces?

Kirill Chernyshov 2024-06-12T15:57:04.334199Z

yes, you can register functional spec using resolvable symbol, either fully qualified or aliased

👍 1
evocatus 2024-06-12T15:58:38.920539Z

That's great, thanks !

seancorfield 2024-06-12T16:58:18.150979Z

Take a look at next.jdbc for an example of specs in one namespace, but function definitions in another (so they're optional for users).

evocatus 2024-06-12T15:58:24.630069Z

How to spec (with fdef) multi-arity functions? https://clojure.org/guides/learn/functions#_multi_arity_functions UPD: it's described in fdef docs:

:args A regex spec for the function arguments as they were a list to be
  passed to apply - in this way, a single spec can handle functions with
  multiple arities
So, looks like we should use one schema to describe all arities at once

peterh 2024-06-14T17:01:52.676489Z

I spec them like this:

(s/fdef foo
  :args (s/alt :ar1 (s/cat :arg1 ::my-spec)
               :ar2 (s/cat :arg1 ::my-spec
                           :arg2 ::my-other-spec)
               …
  :ret  …)
Where I usually use the argument names instead of "arg1" etc. for clarity.

👍 1
Alex Miller (Clojure team) 2024-06-12T16:01:41.307859Z

Correct

👍 1