<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent activity in Spec</title>
<link>https://ask.clojure.org/index.php/activity/clojure/spec</link>
<description>Powered by Question2Answer</description>
<item>
<title>Commented: How to force clojure.spec generator to skip a field</title>
<link>https://ask.clojure.org/index.php/14893/how-to-force-clojure-spec-generator-to-skip-a-field?show=14896#c14896</link>
<description>So, in more generally, `::y` is &amp;quot;something&amp;quot;, `::x` is &amp;quot;can have `::a`&amp;quot;, and the combined generation must make `y` valid but in some way congruent with `x`. Pretty sure the only reasonable way is to change the `y` generator based on the value of `x`. I&amp;#039;ve updated my answer.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14893/how-to-force-clojure-spec-generator-to-skip-a-field?show=14896#c14896</guid>
<pubDate>Thu, 15 Jan 2026 11:21:12 +0000</pubDate>
</item>
<item>
<title>Commented: What is an ideomatic way to use spec for API input validation?</title>
<link>https://ask.clojure.org/index.php/14225/what-is-an-ideomatic-way-to-use-spec-for-api-input-validation?show=14227#c14227</link>
<description>Thanks for giving direction regarding the way to use and the page mentioned.&lt;br /&gt;
&lt;br /&gt;
Reading through the about page, I still don&amp;#039;t understand the exact reason to go with a global store/db for specs.&lt;br /&gt;
The page states:&lt;br /&gt;
&amp;gt; Specs for data structures, attribute values and functions should all be the same and live in a globally-namespaced directory.&lt;br /&gt;
&lt;br /&gt;
But it doesn&amp;#039;t clarify why specs should live in a globally-namespaced directory.&lt;br /&gt;
&lt;br /&gt;
However, I don&amp;#039;t want to challenge the implementation, as I think overall its a great tool. Just wanted to understand why its built that way.&lt;br /&gt;
&lt;br /&gt;
With the current implementation, is there a good reason why map keys declared with :req-un do not allow qualified names in addition to unqualified ones (as that would further simplify my case). One could argue that a :req-un [ :id ] requires an :id keyword to be present. So it could also be ok to have a &amp;quot;more qualified&amp;quot; version as &amp;quot;:user/id&amp;quot; which is also referring to an id.&lt;br /&gt;
&lt;br /&gt;
As an added benefit that could &amp;quot;lift&amp;quot; map keywords to a certain namespace when using conform:&lt;br /&gt;
&lt;br /&gt;
=&amp;gt; (s/conform :qualified/user {:id &amp;quot;some-id&amp;quot;. &amp;nbsp;..})&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{ :qualified/user/id &amp;quot;some-id&amp;quot; }&lt;br /&gt;
&lt;br /&gt;
Does that make sense?&lt;br /&gt;
&lt;br /&gt;
Thanks for sharing your view!</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14225/what-is-an-ideomatic-way-to-use-spec-for-api-input-validation?show=14227#c14227</guid>
<pubDate>Thu, 07 Nov 2024 16:36:29 +0000</pubDate>
</item>
<item>
<title>Retagged: `(s/explain-data (s/coll-of any? :count 1) (range))` hangs</title>
<link>https://ask.clojure.org/index.php/13660/s-explain-data-s-coll-of-any-count-1-range-hangs?show=13660#q13660</link>
<description>&lt;p&gt;&lt;code&gt;(s/explain-data (s/coll-of any? :count 1) (range))&lt;/code&gt; hangs.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;coll-prob&lt;/code&gt; impl has these lines:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(cond
  ...
  (c/and count (not= count (bounded-count count x)))
  [{:path path :pred `(= ~count (c/count ~&#039;%)) :val x :via via :in in}]
  ...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So for all non-counted collections with number of items larger than &lt;code&gt;count&lt;/code&gt;, this branch is never triggered.&lt;br&gt;
Maybe it should use &lt;code&gt;(bounded-count (inc count) x)&lt;/code&gt; instead?&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13660/s-explain-data-s-coll-of-any-count-1-range-hangs?show=13660#q13660</guid>
<pubDate>Wed, 21 Aug 2024 15:38:38 +0000</pubDate>
</item>
<item>
<title>Retagged: `(s/gen ratio?)` throws exceptions</title>
<link>https://ask.clojure.org/index.php/13877/s-gen-ratio-throws-exceptions?show=13877#q13877</link>
<description>&lt;p&gt;&lt;code&gt;(s/gen ratio?)&lt;/code&gt; is &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/spec.alpha/blob/c630a0b8f1f47275e1a476dcdf77507316bad5bc/src/main/clojure/clojure/spec/gen/alpha.clj#L187&quot;&gt;implemented&lt;/a&gt; as &lt;code&gt;(gen/such-that ratio? gen/ratio)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The problem is that about 10% of the time &lt;code&gt;gen/ratio&lt;/code&gt; returns a whole number, which fails the &lt;code&gt;ratio?&lt;/code&gt; predicate. If that happens 10 times in a row, &lt;code&gt;gen/such-that&lt;/code&gt; throws an exception.&lt;/p&gt;
&lt;p&gt;With a large enough sample size, &lt;code&gt;(s/gen ratio?)&lt;/code&gt; reliably fails:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(dorun (gen/sample (s/gen ratio?) 10000000))

Execution error (ExceptionInfo) at clojure.test.check.generators/fn (generators.cljc:435).
Couldn&#039;t satisfy such-that predicate after 10 tries.
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A quick fix is to increase the &lt;code&gt;max-tries&lt;/code&gt; param for &lt;code&gt;such-that&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(dorun (gen/sample (gen/such-that ratio? gen/ratio 100) 10000000))

=&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I do however also find it odd that &lt;code&gt;(s/gen ratio?)&lt;/code&gt; always generates &lt;code&gt;Ratio&lt;/code&gt;s, but &lt;code&gt;gen/ratio&lt;/code&gt; generates a mixture of ratios and integers. So perhaps a better fix would be to update &lt;code&gt;gen/ratio&lt;/code&gt; to not generate integers?&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13877/s-gen-ratio-throws-exceptions?show=13877#q13877</guid>
<pubDate>Wed, 22 May 2024 19:26:58 +0000</pubDate>
</item>
<item>
<title>Commented: clojure spec vs plumatic schema</title>
<link>https://ask.clojure.org/index.php/13817/clojure-spec-vs-plumatic-schema?show=13832#c13832</link>
<description>And I should also note that my comment about Schema not being updated for a couple of years wasn&amp;#039;t specifically a negative, only a comparative: Spec has been updated and Malli is very, very actively maintained.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13817/clojure-spec-vs-plumatic-schema?show=13832#c13832</guid>
<pubDate>Fri, 19 Apr 2024 19:04:34 +0000</pubDate>
</item>
<item>
<title>Commented: spec 1 :count fails uninformatively</title>
<link>https://ask.clojure.org/index.php/13656/spec-1-count-fails-uninformatively?show=13662#c13662</link>
<description>Thanks, I appreciate the observations. I disagree on &amp;nbsp;&amp;quot;[...] actually prints the value itself, so it&amp;#039;s trivial to see the count&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
It&amp;#039;s not trivial for a human to count 42 or 1024 items in a vector :) spec explanations should be there to make our lives easier.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13656/spec-1-count-fails-uninformatively?show=13662#c13662</guid>
<pubDate>Fri, 02 Feb 2024 21:21:27 +0000</pubDate>
</item>
<item>
<title>Commented: Surprising behaviour</title>
<link>https://ask.clojure.org/index.php/13390/surprising-behaviour?show=13443#c13443</link>
<description>I have also found some cases like this:&lt;br /&gt;
```&lt;br /&gt;
(def test-data (rest &amp;#039;(defn l81!E!_P4.*333?1-_5j ([[:as !t!qI!B4.E4] &amp;amp; Np] nil) :kCMH6DT9E :!PM!:p &amp;quot;@o5Pb.y&amp;quot;)))&lt;br /&gt;
=&amp;gt; #&amp;#039;cursive.extensions.specs/test-data&lt;br /&gt;
(s/conform :clojure.core.specs.alpha/defn-args test-data)&lt;br /&gt;
=&amp;gt; :clojure.spec.alpha/invalid&lt;br /&gt;
(s/explain-str :clojure.core.specs.alpha/defn-args test-data)&lt;br /&gt;
=&amp;gt; &amp;quot;Success!\n&amp;quot;&lt;br /&gt;
```&lt;br /&gt;
I&amp;#039;m inclined to think that conform is wrong here, since the data looks valid for defn to me.&lt;br /&gt;
&lt;br /&gt;
Some more short cases that look valid:&lt;br /&gt;
```&lt;br /&gt;
(defn f+55_Uu+*5RmN.7.5J1 ([VWa.7Y4] :N0) :+_z7+:*)&lt;br /&gt;
&lt;br /&gt;
(defn Y {} ([]) ([&amp;amp; []] _kP_2_A-*du1 &amp;quot;FI5&amp;quot;) nil)&lt;br /&gt;
&lt;br /&gt;
(defn I+ {} ([&amp;amp; [:as .]] :y:w?_ n :+:T*7*r-w2 nil &amp;quot; */&amp;quot;) &amp;quot;&amp;quot; nil)&lt;br /&gt;
```</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13390/surprising-behaviour?show=13443#c13443</guid>
<pubDate>Wed, 08 Nov 2023 03:48:43 +0000</pubDate>
</item>
<item>
<title>Commented: Should s/keys error on bad arg keys (not :req, :req-un, etc)?</title>
<link>https://ask.clojure.org/index.php/13200/should-s-keys-error-on-bad-arg-keys-not-req-req-un-etc?show=13205#c13205</link>
<description>OK thanks for the reply. At least there&amp;#039;s Kondo.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13200/should-s-keys-error-on-bad-arg-keys-not-req-req-un-etc?show=13205#c13205</guid>
<pubDate>Sat, 26 Aug 2023 16:27:28 +0000</pubDate>
</item>
<item>
<title>Closed: Should the actual function be called when an fspec is being validated?</title>
<link>https://ask.clojure.org/index.php/12966/should-the-actual-function-called-when-fspec-being-validated?show=12966#q12966</link>
<description>&lt;p&gt;TL;DR&lt;br&gt;
When instrumentation is turned on, spec validates a fspec that appears in the :args of another fspec by calling the actual function with generated arguments, which if it performs side effects could lead to unexpected and incorrect results.&lt;/p&gt;
&lt;p&gt;The problem&lt;br&gt;
If we have the following functions and specs&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn create-generator []
  (let [counter (atom [])]
    (fn [&amp;amp; _]
      (swap! counter inc))))

(s/def ::my-generator (s/fspec :args (s/cat :identifier-arguments (s/* string?))
                               :ret integer?))

(defn my-fn [generator]
  (generator))

(s/fdef my-fn
        :args (s/cat :my-context ::my-generator)
        :ret string?)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Calling (my-fn (create-generator)) will return different results depending on instrumentation being enabled or not.&lt;br&gt;
With instrumentation enabled, our function is being called 21 times more than the single invocation we&#039;ll be expecting (hint: this numbers comes from clojure.alpha.spec/&lt;em&gt;fspec-iterations&lt;/em&gt;).&lt;br&gt;
This happens because my-fn&#039;s spec has args, and in such case clojure.alpha.spec.test/instrument does the following:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;If a var has an :args fn-spec, sets the var&#039;s root binding to a fn&lt;br&gt;
that checks arg conformance (throwing an exception on failure) before&lt;br&gt;
delegating to the original fn.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This means it must check if the function received as argument conforms the ::my-generator spec, which is itself an fspec. For that it calls the fspec reified conform* and that implementation runs a quick-check style test, generating random arguments based on the :args spec and calling the actual function. This can be observed by creating an exception in the function returned by create-generator, the stacktrace looks like this&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&#039;[[clojure.test_clojure.fspec_bug_test$create_generator$fn__5468 doInvoke &quot;fspec_bug_test.clj&quot; 4]
  [clojure.lang.RestFn applyTo &quot;RestFn.java&quot; 137]
  [clojure.core$apply invokeStatic &quot;core.clj&quot; 665]
  [clojure.core$apply invoke &quot;core.clj&quot; 660]
  [clojure.alpha.spec.impl$call_valid_QMARK_ invokeStatic &quot;impl.clj&quot; 1616]
  [clojure.alpha.spec.impl$call_valid_QMARK_ invoke &quot;impl.clj&quot; 1612]
  [clojure.alpha.spec.impl$validate_fn$fn__4117 invoke &quot;impl.clj&quot; 1627]
  [clojure.lang.AFn applyToHelper &quot;AFn.java&quot; 154]
  [clojure.lang.AFn applyTo &quot;AFn.java&quot; 144]
  [clojure.core$apply invokeStatic &quot;core.clj&quot; 665]
  [clojure.core$apply invoke &quot;core.clj&quot; 660]
  [clojure.test.check.properties$apply_gen$fn__5403$fn__5404 invoke &quot;properties.cljc&quot; 31]
  [clojure.test.check.properties$apply_gen$fn__5403 invoke &quot;properties.cljc&quot; 30]
  [clojure.test.check.rose_tree$fmap invokeStatic &quot;rose_tree.cljc&quot; 77]
  [clojure.test.check.rose_tree$fmap invoke &quot;rose_tree.cljc&quot; 73]
  [clojure.test.check.generators$fmap$fn__4871 invoke &quot;generators.cljc&quot; 104]
  [clojure.test.check.generators$gen_fmap$fn__4845 invoke &quot;generators.cljc&quot; 59]
  [clojure.test.check.generators$call_gen invokeStatic &quot;generators.cljc&quot; 43]
  [clojure.test.check.generators$call_gen invoke &quot;generators.cljc&quot; 39]
  [clojure.test.check$quick_check invokeStatic &quot;check.cljc&quot; 211]
  [clojure.test.check$quick_check doInvoke &quot;check.cljc&quot; 59]
  [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 425]
  [clojure.lang.AFn applyToHelper &quot;AFn.java&quot; 156]
  [clojure.lang.RestFn applyTo &quot;RestFn.java&quot; 132]
  [clojure.core$apply invokeStatic &quot;core.clj&quot; 665]
  [clojure.core$apply invoke &quot;core.clj&quot; 660]
  [clojure.alpha.spec.gen$quick_check invokeStatic &quot;gen.clj&quot; 32]
  [clojure.alpha.spec.gen$quick_check doInvoke &quot;gen.clj&quot; 30]
  [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 421]
  [clojure.alpha.spec.impl$validate_fn invokeStatic &quot;impl.clj&quot; 1628]
  [clojure.alpha.spec.impl$validate_fn invoke &quot;impl.clj&quot; 1623]
  [clojure.alpha.spec.impl$fspec_impl$reify__4124 conform_STAR_ &quot;impl.clj&quot; 1646]
  [clojure.alpha.spec$conform invokeStatic &quot;spec.clj&quot; 245]
  [clojure.alpha.spec$conform invoke &quot;spec.clj&quot; 237]
  [clojure.alpha.spec$conform invokeStatic &quot;spec.clj&quot; 241]
  [clojure.alpha.spec$conform invoke &quot;spec.clj&quot; 237]
  [clojure.alpha.spec.impl$dt invokeStatic &quot;impl.clj&quot; 219]
  [clojure.alpha.spec.impl$dt invoke &quot;impl.clj&quot; 214]
  [clojure.alpha.spec.impl$dt invokeStatic &quot;impl.clj&quot; 215]
  [clojure.alpha.spec.impl$dt invoke &quot;impl.clj&quot; 214]
  [clojure.alpha.spec.impl$deriv invokeStatic &quot;impl.clj&quot; 1426]
  [clojure.alpha.spec.impl$deriv invoke &quot;impl.clj&quot; 1420]
  [clojure.alpha.spec.impl$deriv invokeStatic &quot;impl.clj&quot; 1434]
  [clojure.alpha.spec.impl$deriv invoke &quot;impl.clj&quot; 1420]
  [clojure.alpha.spec.impl$re_conform invokeStatic &quot;impl.clj&quot; 1564]
  [clojure.alpha.spec.impl$re_conform invoke &quot;impl.clj&quot; 1555]
  [clojure.alpha.spec.impl$as_regex_spec$fn__3849 invoke &quot;impl.clj&quot; 1238]
  [clojure.alpha.spec.protocols$eval1958$fn__2056$G__1939__2067 invoke &quot;protocols.clj&quot; 11]
  [clojure.alpha.spec$conform invokeStatic &quot;spec.clj&quot; 245]
  [clojure.alpha.spec$conform invoke &quot;spec.clj&quot; 237]
  [clojure.alpha.spec$conform invokeStatic &quot;spec.clj&quot; 241]
  [clojure.alpha.spec$conform invoke &quot;spec.clj&quot; 237]
  [clojure.alpha.spec.test$spec_checking_fn$conform_BANG___4398 invoke &quot;test.clj&quot; 131]
  [clojure.alpha.spec.test$spec_checking_fn$fn__4400 doInvoke &quot;test.clj&quot; 150]
  [clojure.lang.RestFn invoke &quot;RestFn.java&quot; 408]
  [clojure.test_clojure.fspec_bug_test$eval5473 invokeStatic &quot;fspec_bug_test.clj&quot; 2]
  [clojure.test_clojure.fspec_bug_test$eval5473 invoke &quot;fspec_bug_test.clj&quot; 44]
  ...]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, the problem can be reduced to the fspec implementation of conform* since by just calling s/valid? will show the behavior of the function being called, but this is uncommon, while having functions annotated and turning on instrumentation during tests is a common practice, that&#039;s why the example in this PR shows a concrete problematic scenario with the current implementation of fspec.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;; This already shows the actual function being called, but is an unrealistic example
(s/valid? ::my-generator (fn [&amp;amp; args]
                           (println args)
                           1))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12966/should-the-actual-function-called-when-fspec-being-validated?show=12966#q12966</guid>
<pubDate>Tue, 30 May 2023 04:53:15 +0000</pubDate>
</item>
<item>
<title>Answer selected: Inconsistent results from s/valid? and s/explain when trying to spec list of values</title>
<link>https://ask.clojure.org/index.php/12957/inconsistent-results-from-valid-explain-when-trying-values?show=12958#a12958</link>
<description>&lt;p&gt;Seems like you have narrowed it down to &lt;code&gt;spec-tools&lt;/code&gt; and that &lt;code&gt;clojure.spec.alpha&lt;/code&gt; is not to blame here. Given that, I&#039;d post an issue to &lt;code&gt;spec-tools&lt;/code&gt;&#039; GitHub.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12957/inconsistent-results-from-valid-explain-when-trying-values?show=12958#a12958</guid>
<pubDate>Thu, 25 May 2023 03:02:01 +0000</pubDate>
</item>
<item>
<title>Comment edited: Full specs for clojure.core in core.specs.alpha</title>
<link>https://ask.clojure.org/index.php/12851/full-specs-for-clojure-core-in-core-specs-alpha?show=12866#c12866</link>
<description>Not really, not completely. kondo&amp;#039;s system for type checking is a bit patched together. It has to put in a custom function every time it has to do a conditional type check, for instance.&lt;br /&gt;
&lt;br /&gt;
Kondo has a custom function for core.into that says to make the return type the same as the type of the collection passed in as its first argument. Already there is a ticket on their JIRA board to add that to another function, and it doesn&amp;#039;t follow suit on a variety of other functions either, like the function inc. If you pass an int to inc, Kondo doesn&amp;#039;t know if the output is still an int.&lt;br /&gt;
&lt;br /&gt;
I. E.&lt;br /&gt;
This code: (nth [1 2 3] 1.5) throws an error in kondo (which is incorrect btw, nth is defined for non-integers)&lt;br /&gt;
But this code (nth [1 2 3] (inc 0.5)) comes through with no error.&lt;br /&gt;
&lt;br /&gt;
If this continues, kondo will have to end up with a huge amount of logic, that doesn&amp;#039;t necessarily belong in their codebase.&lt;br /&gt;
&lt;br /&gt;
If a user wanted to implement or extend logic like that, it would be difficult to do so. There is no easy and well understood means of defining that. I was hoping spec would grow to become a standard way for developers to encode necessary type logic within their own codebases in a TypeScript-y way. For instance, if it was important in your codebase to define a collection as a collection of ints, or a collection of some custom type for your database, that would get communicated to kondo, and it would be able to perform logic on that, and see several transformations down the line if something will fail. Spec and Malli already have some systems to do that, but kondo doesn&amp;#039;t have the logic yet to complete it.&lt;br /&gt;
&lt;br /&gt;
I am unsure if the appropriate logic for making this kind of analysis belongs in kondo itself, or if it belongs somewhere in the clojure codebase, since it is solely dependent on clojure&amp;#039;s api. Nor do I know if spec or spec2 are the right places to hold it. That&amp;#039;s why I posted this question here.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12851/full-specs-for-clojure-core-in-core-specs-alpha?show=12866#c12866</guid>
<pubDate>Mon, 17 Apr 2023 15:15:06 +0000</pubDate>
</item>
<item>
<title>Answer selected: (s/valid? ::my-spec) succeeds, but (s/valid? (s/and ::my-spec ::my-spec)) fails</title>
<link>https://ask.clojure.org/index.php/12743/s-valid-my-spec-succeeds-but-s-valid-s-and-my-spec-my-spec-fails?show=12745#a12745</link>
<description>&lt;p&gt;s/and flows the &lt;strong&gt;conformed&lt;/strong&gt; result through the s/and specs, so if the conformed result is different (often due to s/or, s/cat, s/alt) then this will not necessarily work.&lt;/p&gt;
&lt;p&gt;If you want to avoid conforming the s/or to a different value, you can wrap that spec in s/nonconforming.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12743/s-valid-my-spec-succeeds-but-s-valid-s-and-my-spec-my-spec-fails?show=12745#a12745</guid>
<pubDate>Wed, 22 Mar 2023 18:45:30 +0000</pubDate>
</item>
<item>
<title>Answered: clojure.alpha.spec/gen can&#039;t generate samples for schemas containing unregistered specs</title>
<link>https://ask.clojure.org/index.php/12731/clojure-generate-samples-schemas-containing-unregistered?show=12758#a12758</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/TDEPS-243&quot;&gt;https://clojure.atlassian.net/browse/TDEPS-243&lt;/a&gt;&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12731/clojure-generate-samples-schemas-containing-unregistered?show=12758#a12758</guid>
<pubDate>Mon, 13 Mar 2023 15:30:05 +0000</pubDate>
</item>
<item>
<title>Answer selected: Why isn&#039;t a spec for :clojure.spec.alpha/problems?</title>
<link>https://ask.clojure.org/index.php/12680/why-isnt-a-spec-for-clojure-spec-alpha-problems?show=12706#a12706</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2748&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2748&lt;/a&gt;&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12680/why-isnt-a-spec-for-clojure-spec-alpha-problems?show=12706#a12706</guid>
<pubDate>Tue, 07 Mar 2023 12:59:21 +0000</pubDate>
</item>
<item>
<title>Answer selected: `(s/merge X Y)` disables conformation for `:*-un` keys in X</title>
<link>https://ask.clojure.org/index.php/12573/s-merge-x-y-disables-conformation-for-un-keys-in-x?show=12574#a12574</link>
<description>&lt;p&gt;This is the expected behavior. s/merge does not &quot;flow&quot; conformed like s/and. You only get the conformed values per the last spec in the merge.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12573/s-merge-x-y-disables-conformation-for-un-keys-in-x?show=12574#a12574</guid>
<pubDate>Sat, 04 Feb 2023 18:05:57 +0000</pubDate>
</item>
<item>
<title>Commented: how clojure.spec.alpha validation correctness is reasoned about?</title>
<link>https://ask.clojure.org/index.php/12473/clojure-spec-alpha-validation-correctness-reasoned-about?show=12477#c12477</link>
<description>&amp;quot;Certainly, doing more would be better, but would really like to spend some time eventually on generatively creating specs and values for testing (but this is tricky without spec!)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Does it make sense to generate specs _somehow_ then generate values via generated specs generators and validate values via generated specs?&lt;br /&gt;
As a result problem of values generating is resolved by using generated spec generators what brings coupling for sure on the whole generators logic layer so validation responsibility is not tested in isolation.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12473/clojure-spec-alpha-validation-correctness-reasoned-about?show=12477#c12477</guid>
<pubDate>Wed, 14 Dec 2022 19:15:22 +0000</pubDate>
</item>
<item>
<title>Commented: Is it useful to extend fspec to enable the expression of constraints on a function such as commutativity.</title>
<link>https://ask.clojure.org/index.php/12406/useful-extend-expression-constraints-function-commutativity?show=12408#c12408</link>
<description>To be honest no real problem to solve - I am an addict of property based / generative testing and so I have these already as tests for the functions in question. &lt;br /&gt;
&lt;br /&gt;
However I like spec and it seems nice to me to maybe be able to have this specification style info available in an fspec, and thus to drive the same testing from there. &lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m somewhat new to using Clojure and trying to push myself to pick some problem up that I can use to learn more deeply, and that will challenge me a bit; so I was mainly just wondering if it seemed useful, or if it was just me.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12406/useful-extend-expression-constraints-function-commutativity?show=12408#c12408</guid>
<pubDate>Mon, 28 Nov 2022 10:41:47 +0000</pubDate>
</item>
<item>
<title>Commented: How hard is it to learn Clojure?</title>
<link>https://ask.clojure.org/index.php/12340/how-hard-is-it-to-learn-clojure?show=12344#c12344</link>
<description>Agreed, it can be highly variable. Some people with the right background (some Java and some Lisp/Scheme experience helps) can be productive in 2-4 weeks, others find it takes 3-6 months to feel proficient. Having an active guide is a huge help and the kind folks in the beginners channel are very helpful.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://clojure.org/community/resources&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.org/community/resources&lt;/a&gt; has a lot of useful links but which are helpful will really depend a lot on your background and what programming worlds you&amp;#039;re familiar with.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12340/how-hard-is-it-to-learn-clojure?show=12344#c12344</guid>
<pubDate>Sun, 30 Oct 2022 16:05:30 +0000</pubDate>
</item>
<item>
<title>Answered: Spec2 - Bug on nested schema specs</title>
<link>https://ask.clojure.org/index.php/12228/spec2-bug-on-nested-schema-specs?show=12339#a12339</link>
<description>&lt;p&gt; Indirect spec references often result in this exception. There are a couple of workarounds:&lt;/p&gt;
&lt;p&gt;Defining :entity/ref with a single-clause s/and:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/def :entity/ref (s/and ::another-entity))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or registering it with s/register and s/get-spec&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/register :entity/ref (s/get-spec ::another-entity))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In any case, this is probably not the intended behavior.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12228/spec2-bug-on-nested-schema-specs?show=12339#a12339</guid>
<pubDate>Fri, 28 Oct 2022 15:41:56 +0000</pubDate>
</item>
<item>
<title>Answer selected: Typo in clojure.spec.alpha’s keys docstring</title>
<link>https://ask.clojure.org/index.php/12275/typo-in-clojure-spec-alphas-keys-docstring?show=12278#a12278</link>
<description>&lt;p&gt;Thanks, fixed in spec and spec 2.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12275/typo-in-clojure-spec-alphas-keys-docstring?show=12278#a12278</guid>
<pubDate>Tue, 04 Oct 2022 05:21:43 +0000</pubDate>
</item>
<item>
<title>Commented: Spec 2: Closed Generators</title>
<link>https://ask.clojure.org/index.php/12198/spec-2-closed-generators?show=12203#c12203</link>
<description>Alright, thanks for your answer.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12198/spec-2-closed-generators?show=12203#c12203</guid>
<pubDate>Tue, 13 Sep 2022 16:02:08 +0000</pubDate>
</item>
<item>
<title>Closed: Accessing :column, :line &amp; :file meta data of a Spec</title>
<link>https://ask.clojure.org/index.php/12199/accessing-column-line-file-meta-data-of-a-spec?show=12199#q12199</link>
<description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;is it possible to somehow get at the :column, :line and :file&lt;br&gt;
information of where a Spec was defined?&lt;/p&gt;
&lt;p&gt;I believe this information could be collected from &lt;code&gt;(meta &amp;amp;form)&lt;/code&gt; in&lt;br&gt;
the &lt;code&gt;s/def&lt;/code&gt; macro but isn&#039;t stored anywhere right now.&lt;/p&gt;
&lt;p&gt;I would be great to have this information available to support REPL&lt;br&gt;
based tooling for features like &quot;jump to definition&quot;.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12199/accessing-column-line-file-meta-data-of-a-spec?show=12199#q12199</guid>
<pubDate>Tue, 13 Sep 2022 14:48:48 +0000</pubDate>
</item>
<item>
<title>Retagged: Clojure Spec 2. Unexpected s/with-gen behaviour</title>
<link>https://ask.clojure.org/index.php/12185/clojure-spec-2-unexpected-s-with-gen-behaviour?show=12185#q12185</link>
<description>&lt;p&gt;When using regular expression operators (&lt;code&gt;s/alt&lt;/code&gt; &lt;code&gt;s/cat&lt;/code&gt; etc ) to describe sequences, &lt;code&gt;s/with-gen&lt;/code&gt; doesn&#039;t work as I would have expected. It completely ignores the generator passed to the definition. Eg:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(require &#039;[clojure.alpha.spec :as s])
(require &#039;[clojure.alpha.spec.gen :as gen])
(s/def ::some-spec 
 (s/with-gen string? (constantly (gen/return &quot;olar&quot;))))

(gen/sample (s/gen ::some-spec))
 ;;=&amp;gt; (&quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot; &quot;olar&quot;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt; The above generator works as I would expected, now if we try to create a similar one for s/alt we get unexpected results: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/def ::some-other-spec 
 (s/with-gen
  (s/alt :greetings #{:olar :oizito :oi :hello :hey :yo :hallo}
             :farewell #{:bye :bye-bye :hasta-la-vista :tchussy :tchau-kakao})
  (constantly (gen/return [:tchau-kakao]))))

(gen/sample (s/gen ::some-other-spec))
;;=&amp;gt; =&amp;gt; ([:olar] [:hasta-la-vista] [:hallo] [:hallo] [:tchussy] [:oi] [:bye-bye] [:tchussy] [:tchau-kakao] [:yo])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is this a bug or is it expected somehow?&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12185/clojure-spec-2-unexpected-s-with-gen-behaviour?show=12185#q12185</guid>
<pubDate>Fri, 09 Sep 2022 18:17:50 +0000</pubDate>
</item>
<item>
<title>Closed: Is Clojure is the only Lisp designed with Concurrency?</title>
<link>https://ask.clojure.org/index.php/12130/is-clojure-is-the-only-lisp-designed-with-concurrency?show=12130#q12130</link>
<description>&lt;p&gt;I believe that Clojure is not the only Lisp build in with concurrency. From what I understand, LispWorks and perhaps Allegro Lisp is also concurrent in design. As for whether the Eclipse Lisp plug-in is concurrent, I am not sure as it relies on SBCL or CLISP for the environment. And Racket is also another Lisp dialect which Prof Matthias Felleisen has assured me that it is also a AI language, but as for concurrency I am not too sure. I believe the way forward other than create a new fork with Clojure would be better to engage the Lisp steering committee to change/add concurrency into the Common Lisp language. &lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12130/is-clojure-is-the-only-lisp-designed-with-concurrency?show=12130#q12130</guid>
<pubDate>Fri, 26 Aug 2022 12:55:49 +0000</pubDate>
</item>
<item>
<title>Answered: Spec alias behavior</title>
<link>https://ask.clojure.org/index.php/12043/spec-alias-behavior?show=12044#a12044</link>
<description>&lt;blockquote&gt;&lt;p&gt;its definition is arguably the most confusing for other users, because it sounds like s/and should have multiple arguments.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That&#039;s exactly the case. &lt;code&gt;s/and&lt;/code&gt; is similar to &lt;code&gt;and&lt;/code&gt; - the most common usage is with multiple arguments, although you can pass just one, or even none.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/12043/spec-alias-behavior?show=12044#a12044</guid>
<pubDate>Mon, 11 Jul 2022 16:33:50 +0000</pubDate>
</item>
<item>
<title>Answer selected: Add support for checking instrumented syms in clojure.spec.test.alpha</title>
<link>https://ask.clojure.org/index.php/11816/support-checking-instrumented-syms-clojure-spec-test-alpha?show=11875#a11875</link>
<description>&lt;p&gt;Logged as &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2706&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2706&lt;/a&gt;&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11816/support-checking-instrumented-syms-clojure-spec-test-alpha?show=11875#a11875</guid>
<pubDate>Sat, 07 May 2022 11:08:35 +0000</pubDate>
</item>
<item>
<title>Answer selected: Does fdef support multimethods?</title>
<link>https://ask.clojure.org/index.php/11101/does-fdef-support-multimethods?show=11102#a11102</link>
<description>&lt;p&gt;From what I can tell, &lt;code&gt;fdef&lt;/code&gt; does seem to work fine with multimethods, although if you&#039;re going to use &lt;code&gt;get-method&lt;/code&gt; on an instrumented multimethod you need to keep around a reference/binding to the original multimethod before it gets wrapped by &lt;code&gt;instrument&lt;/code&gt;, and call &lt;code&gt;get-method&lt;/code&gt; on that original. (This is arguably as designed/documented since instrumenting expressly replaces the original fn. It would be neat if instrumenting wrapped each method within the multi rather than sitting (as it seems) above the dispatch, but the folks who built instrumenting have probably thought more about this than I have....)&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11101/does-fdef-support-multimethods?show=11102#a11102</guid>
<pubDate>Thu, 03 Feb 2022 17:44:48 +0000</pubDate>
</item>
<item>
<title>Answer selected: Unresolvable symbol safe for spec def?</title>
<link>https://ask.clojure.org/index.php/11543/unresolvable-symbol-safe-for-spec-def?show=11544#a11544</link>
<description>&lt;p&gt;The registry is intended to hold two types of keys: keywords (named specs) and symbols that resolve to functions for function specs. Because the use for the latter is function specs, they can&#039;t really be effectively resolved unless the symbol resolves (hence the docs).&lt;/p&gt;
&lt;p&gt;However, we do not validate that a symbol is resolvable at the time of s/def, and in fact we don&#039;t want to because that allows specs to be defined either before or after the function it refers to.&lt;/p&gt;
&lt;p&gt;You should never be calling s/def with a symbol directly as in this example (it is allowed because that&#039;s how s/fdef does things under the hood).&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11543/unresolvable-symbol-safe-for-spec-def?show=11544#a11544</guid>
<pubDate>Thu, 03 Feb 2022 14:28:25 +0000</pubDate>
</item>
<item>
<title>Commented: The specs for `defn` do not roundtrip using `conform` / `unform`</title>
<link>https://ask.clojure.org/index.php/11241/the-specs-for-defn-do-not-roundtrip-using-conform-unform?show=11244#c11244</link>
<description>thanks - I couldn&amp;#039;t find it searching for `unform` but maybe I was holding it wrong</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11241/the-specs-for-defn-do-not-roundtrip-using-conform-unform?show=11244#c11244</guid>
<pubDate>Wed, 03 Nov 2021 15:55:36 +0000</pubDate>
</item>
<item>
<title>Answered: defn spec does not unform arg list vectors</title>
<link>https://ask.clojure.org/index.php/4620/defn-spec-does-not-unform-arg-list-vectors?show=11243#a11243</link>
<description>&lt;p&gt;For the specific case of &quot;regex coll that must also be a vector&quot;, it&#039;s not really possible to achieve this with spec 1 and make it work for all of conform, unform, and gen.&lt;/p&gt;
&lt;p&gt;In spec 2, we have added support for non-flowing s/and (currently called s/and- but that name is still in flux, might end up as s/union or something else), which is needed to add s/cat variants that additionally enforce the coll is either a vector or sequence as s/catv and s/cats.&lt;/p&gt;
&lt;p&gt;Eventually we will rework the core.specs using spec2 and use s/catv for the defn arg vector which will resolve this issue.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/4620/defn-spec-does-not-unform-arg-list-vectors?show=11243#a11243</guid>
<pubDate>Wed, 03 Nov 2021 15:45:27 +0000</pubDate>
</item>
<item>
<title>Answered: s/merge causes failure to roundtrip conform then unform</title>
<link>https://ask.clojure.org/index.php/3355/s-merge-causes-failure-to-roundtrip-conform-then-unform?show=11240#a11240</link>
<description>&lt;p&gt;Also see this &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2021&quot;&gt;JIRA ticket&lt;/a&gt; for how &lt;code&gt;conform&lt;/code&gt; / &lt;code&gt;unform&lt;/code&gt; using specs for &lt;code&gt;defn&lt;/code&gt; fails.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/3355/s-merge-causes-failure-to-roundtrip-conform-then-unform?show=11240#a11240</guid>
<pubDate>Wed, 03 Nov 2021 15:06:37 +0000</pubDate>
</item>
<item>
<title>Commented: Why does s/conform transform data?</title>
<link>https://ask.clojure.org/index.php/11230/why-does-s-conform-transform-data?show=11232#c11232</link>
<description>Thanks! And sorry, the question drifted in draft.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11230/why-does-s-conform-transform-data?show=11232#c11232</guid>
<pubDate>Sat, 30 Oct 2021 21:33:20 +0000</pubDate>
</item>
<item>
<title>Commented: s/conform of s/map-of does not conform keys, is that expected?</title>
<link>https://ask.clojure.org/index.php/11217/s-conform-of-s-map-of-does-not-conform-keys-is-that-expected?show=11222#c11222</link>
<description>Thanks Alex!</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11217/s-conform-of-s-map-of-does-not-conform-keys-is-that-expected?show=11222#c11222</guid>
<pubDate>Thu, 28 Oct 2021 16:15:40 +0000</pubDate>
</item>
<item>
<title>Retagged: Spec `form` on `keys` missing namespace for `or`</title>
<link>https://ask.clojure.org/index.php/11087/spec-form-on-keys-missing-namespace-for-or?show=11087#q11087</link>
<description>&lt;p&gt;&lt;code&gt;[org.clojure/clojure &quot;1.11.0-alpha2&quot;]&lt;/code&gt;&lt;br&gt;
&lt;code&gt;clojure.spec.alpha&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Repro (see &lt;code&gt;or&lt;/code&gt; inside &lt;code&gt;keys&lt;/code&gt;):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/def :x/foo int?)
(s/def :x/bar string?)

(s/form (s/keys :req-un [(or :x/foo :x/bar)]))
; =&amp;gt; (clojure.spec.alpha/keys :req-un [(or :x/foo :x/bar)])

(s/form (s/and (s/keys :req-un [(or :x/foo :x/bar)])))
;=&amp;gt; (clojure.spec.alpha/and (clojure.spec.alpha/keys :req-un [(clojure.core/or :x/foo :x/bar)]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Is there a way to force &lt;code&gt;or&lt;/code&gt; to be namespaced in the first &lt;code&gt;form&lt;/code&gt;?&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11087/spec-form-on-keys-missing-namespace-for-or?show=11087#q11087</guid>
<pubDate>Mon, 27 Sep 2021 23:12:06 +0000</pubDate>
</item>
<item>
<title>(s/form (s/multi-spec ...)) returns a list with non-symbolic objects</title>
<link>https://ask.clojure.org/index.php/10969/s-form-s-multi-spec-returns-a-list-with-non-symbolic-objects</link>
<description>&lt;p&gt;My understanding is that &lt;code&gt;s/form&lt;/code&gt; is expected to return symbolic lists that can be passed to &lt;code&gt;eval&lt;/code&gt;. Forms of multi-spec specs don&#039;t behave that way, returning retag as evaluated value (e.g. a function instance).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn retag [x v]
  (assoc (vec x) 0 v))

(defmulti command first)

(s/form (s/multi-spec command retag))
=&amp;gt; (clojure.spec.alpha/multi-spec 
    current.ns/command
    #object[current.ns$retag 0x708d0436 current.ns$retag@708d0436])

;; should be something like
=&amp;gt; (clojure.spec.alpha/multi-spec 
    current.ns/command 
    current.ns/retag)
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10969/s-form-s-multi-spec-returns-a-list-with-non-symbolic-objects</guid>
<pubDate>Tue, 24 Aug 2021 11:08:11 +0000</pubDate>
</item>
<item>
<title>Commented: In Spec 2, is this a bug?</title>
<link>https://ask.clojure.org/index.php/9145/in-spec-2-is-this-a-bug?show=10875#c10875</link>
<description>Logged as &lt;a href=&quot;https://clojure.atlassian.net/browse/CLJ-2648&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2648&lt;/a&gt; if you want to supply a patch</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9145/in-spec-2-is-this-a-bug?show=10875#c10875</guid>
<pubDate>Thu, 29 Jul 2021 00:39:18 +0000</pubDate>
</item>
<item>
<title>Retagged: Spec2: Use case for multi-spec as Schema provider</title>
<link>https://ask.clojure.org/index.php/10696/spec2-use-case-for-multi-spec-as-schema-provider?show=10696#q10696</link>
<description>&lt;p&gt;I have a scenario where I&#039;d like to define some attributes that are internal and common, and some other attributes that are external and dynamic, both related to the same &quot;things&quot;. Specifically, I am trying to model a trading library. There are many different exchanges/brokers/services, but all of them talk about similar/equivalent things.&lt;br&gt;
   Let&#039;s take the example of an order, you can have some attributes that can be common in all services (they don&#039;t necessarily appear on all services):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(spec/def :order/id string?)
(spec/def :order/quantity number?)
(spec/def :order/side #{:buy :sell})
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, every external service can have specific attributes related to how that service handles orders:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(spec/def :service1-order/execution-instructions (spec/coll-of string?))
(spec/def :service2-order/iceberg-quantity (spec/coll-of string?))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I was thinking on having a multi-spec returning schemas, so each service can define what schema to use for an order, on a key like :service/name, but all of them can be &quot;selected&quot; from :order/order. &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defmulti order-schema :service/name)

(defmethod order-schema :service1
  [_]
  (spec/schema [:order/id :order/quantity :order/side :service1-order/execution-instructions]))

(defmethod order-schema :service2
  [_]
  (spec/schema [:order/id :order/quantity :order/side :service2-order/iceberg-quantity]))

(defmethod order-schema :default
  [_]
  (spec/schema [:order/id :order/quantity :order/side]))

(spec/def :order/order (spec/multi-spec order-schema :service/name))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This can be useful also when nesting objects. Imagine I have an account that will contain orders. The account can also be specced as a multi-spec for each service:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(spec/def :account/id string?)
(spec/def :account/orders (spec/coll-of :order/order))

(spec/def :service1-account/type #{:spot :margin :futures})

(defmulti account-schema :service/id)

(defmethod account-schema :service1
  [_]
  (spec/schema [:account/id :account/orders :service1-account/type]))

(defmethod account-schema :default
  [_]
  (spec/schema [:account/id :account/orders]))

(spec/def :account/account (spec/multi-spec account-schema :service/id))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This would allow to select in the following manner: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(spec/def ::service1-account-info (spec/select :account/account [:service1-account/type :account/orders {:account/orders [:order/id :order/quantity :service1-order/execution-instructions]}]))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This way, external services can specify the information they handle about the common layer domain attributes and entities, as well as specify their specific attributes. The user is able to reuse a set of common functions that operate on the common attributes, and if different services provide these common attributes, they can be used interchangeably, while keeping a way to create functions and selections that are specific to specific services.&lt;/p&gt;
&lt;p&gt;Does this use case make sense? Is there a different way to model this that would be better?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10696/spec2-use-case-for-multi-spec-as-schema-provider?show=10696#q10696</guid>
<pubDate>Wed, 28 Jul 2021 22:00:36 +0000</pubDate>
</item>
<item>
<title>Answer edited: Spec for any map entry whose key has a spec</title>
<link>https://ask.clojure.org/index.php/10684/spec-for-any-map-entry-whose-key-has-a-spec?show=10691#a10691</link>
<description>&lt;p&gt;Thanks to @alexmiller&#039;s answer I was able to home in on this specific solution:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/def :my.spec-ed.key/pair (s/and vector? #(= 2 (count %)) (s/keys*)))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will validate against any previously spec-ed key.&lt;/p&gt;
&lt;p&gt;Of course as Alex points out one can always write a macro, this worked for me, it&#039;s a macro that creates a corresponding -tuple spec for each spec in a namespace, and then &lt;code&gt;(s/or)&lt;/code&gt;s them all together into one master &quot;pairs&quot; spec. The idea is you&#039;d run it just once per ns after the other specs are defined (it does not filter out the specs it itself makes):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defmacro pairs-spec
  [spec-id]
  (let [spec-ns (namespace spec-id)
        ors (-&amp;gt;&amp;gt; (s/registry)
                 (map first)
                 (filter #(= spec-ns (namespace %)))
                 (mapcat (fn [ky] `(~(keyword spec-ns
                                              (str (name ky)
                                                   &quot;-tuple&quot;))
                                    (s/tuple #{~ky} ~ky)))))]
    `(s/def ~spec-id (s/or ~@ors))))

(pairs-spec :my.spec-ed.key/pair)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The latter does not give nice results from &lt;code&gt;(s/explain)&lt;/code&gt; because it builds up one big &lt;code&gt;(s/or)&lt;/code&gt; statement, with one entry for each previously spec-ed key in the namespace. Because of this, and because I don&#039;t want to have to worry about whether all my keys have been spec-ed at the time the macro runs, I am preferring the &lt;code&gt;(s/keys*)&lt;/code&gt; solution above.&lt;/p&gt;
&lt;p&gt;Thanks for the help!!&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10684/spec-for-any-map-entry-whose-key-has-a-spec?show=10691#a10691</guid>
<pubDate>Mon, 14 Jun 2021 21:23:48 +0000</pubDate>
</item>
<item>
<title>Answer selected: Is the defn spec overly restrictive?</title>
<link>https://ask.clojure.org/index.php/10627/is-the-defn-spec-overly-restrictive?show=10630#a10630</link>
<description>&lt;p&gt;No, the spec is not too restrictive. The defn macro does not support this. You can turn off spec macro checking with &lt;code&gt;-Dclojure.spec.skip-macros=true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can write a macro that wraps defn and emits the defn with the eval&#039;ed thing if you like.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10627/is-the-defn-spec-overly-restrictive?show=10630#a10630</guid>
<pubDate>Wed, 19 May 2021 12:27:00 +0000</pubDate>
</item>
<item>
<title>Answer selected: should the docstring of `s/keys` give more information about :req-un?</title>
<link>https://ask.clojure.org/index.php/10589/should-the-docstring-of-keys-give-more-information-about-req?show=10590#a10590</link>
<description>&lt;p&gt;&quot;In addition, the values of &lt;em&gt;all&lt;/em&gt; namespace-qualified keys will be validated (and possibly destructured) by any registered specs.&quot;&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10589/should-the-docstring-of-keys-give-more-information-about-req?show=10590#a10590</guid>
<pubDate>Wed, 12 May 2021 03:59:10 +0000</pubDate>
</item>
<item>
<title>Answered: How could I add metadata to specs?</title>
<link>https://ask.clojure.org/index.php/9414/how-could-i-add-metadata-to-specs?show=10568#a10568</link>
<description>&lt;p&gt;Also see &lt;a rel=&quot;nofollow&quot; href=&quot;https://ask.clojure.org/index.php/731/clojure-spec-def-should-support-an-optional-doc-string&quot;&gt;https://ask.clojure.org/index.php/731/clojure-spec-def-should-support-an-optional-doc-string&lt;/a&gt;&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9414/how-could-i-add-metadata-to-specs?show=10568#a10568</guid>
<pubDate>Wed, 05 May 2021 17:15:16 +0000</pubDate>
</item>
<item>
<title>Answer selected: fdef&#039;s on internal/private functions</title>
<link>https://ask.clojure.org/index.php/10525/fdefs-on-internal-private-functions?show=10527#a10527</link>
<description>&lt;p&gt;Yes, it is expected that fdefs on private functions can be instrumented (it&#039;s just a var wrapper after all).&lt;/p&gt;
&lt;p&gt;I think it may be a good idea to have specs on internal/private functions in an independent namespace so its use can be controlled via load (lib can load it for testing, users would not and would likely not even know it existed). &lt;/p&gt;
&lt;p&gt;Additionally, I think it&#039;s usually a good idea to instrument a set of fdef&#039;ed functions in st/instrument (with st/enumerate-namespace as a helper). &lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10525/fdefs-on-internal-private-functions?show=10527#a10527</guid>
<pubDate>Mon, 26 Apr 2021 18:10:01 +0000</pubDate>
</item>
<item>
<title>Commented: spec fdef validating relationships between arguments</title>
<link>https://ask.clojure.org/index.php/10497/spec-fdef-validating-relationships-between-arguments?show=10506#c10506</link>
<description>Yes, Thanks @alexmiller. The code works now</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10497/spec-fdef-validating-relationships-between-arguments?show=10506#c10506</guid>
<pubDate>Tue, 20 Apr 2021 06:37:56 +0000</pubDate>
</item>
<item>
<title>Comment edited: Unexpected spec failure on namespaced keys not included in :req</title>
<link>https://ask.clojure.org/index.php/10356/unexpected-spec-failure-on-namespaced-keys-not-included-req?show=10360#c10360</link>
<description>&amp;gt; The requiredness is orthogonal to the global meaning of the names.&lt;br /&gt;
&lt;br /&gt;
Thank you for the explanation the above is what I was missing. Global things do make things more difficult to reason about in isolation (imho, maybe obvious). I can see now why things like `select` in `spec2` have popped up.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10356/unexpected-spec-failure-on-namespaced-keys-not-included-req?show=10360#c10360</guid>
<pubDate>Thu, 18 Mar 2021 00:56:58 +0000</pubDate>
</item>
<item>
<title>Retagged: Spec instrumentation does not work with extend-with-metadata</title>
<link>https://ask.clojure.org/index.php/10347/spec-instrumentation-does-not-work-with-extend-with-metadata?show=10347#q10347</link>
<description>&lt;p&gt;Hi there, our code base have embraced &lt;code&gt;extend-with-metadata&lt;/code&gt; protocols since its introduction - we like to have map components rather than records.&lt;/p&gt;
&lt;p&gt;However, the code base and team are big clojure spec users and we were expecting the last form of the following to throw:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns defproto-spec.test
  (:require [clojure.spec.alpha :as s]
            [clojure.spec.test.alpha :as st]))

(defprotocol SpecTest
  :extend-via-metadata true
  (delete [impl id]))

(s/fdef delete-impl
  :args (s/cat :impl any? :id string?))

(defn delete-impl [_ id]
  (println (str &quot;This deletes &quot; id))
  id)

(def impl (with-meta {} {`delete delete-impl}))

(st/instrument)

(delete impl 1) ;; should throw but it doesn&#039;t
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Why were we expecting it to work? &lt;/p&gt;
&lt;p&gt;Maybe because the feature is newer (1.10) and because of the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;defproto-spec.test&amp;gt; (st/instrument)
[defproto-spec.test/delete-me defproto-spec.test/delete-impl]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Unfortunately that&#039;s not that case. I would be willing to work on a patch/document this if is not already in  someone else&#039;s pipeline.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;br&gt;
Andrea.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10347/spec-instrumentation-does-not-work-with-extend-with-metadata?show=10347#q10347</guid>
<pubDate>Thu, 18 Mar 2021 00:10:07 +0000</pubDate>
</item>
<item>
<title>Comment edited: Problems with s/union</title>
<link>https://ask.clojure.org/index.php/10345/problems-with-s-union?show=10355#c10355</link>
<description>Thanks! I submitted &lt;a href=&quot;https://clojure.atlassian.net/browse/CLJ-2613&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2613&lt;/a&gt; as fix to this issue.&lt;br /&gt;
&lt;br /&gt;
I also submitted &lt;a href=&quot;https://clojure.atlassian.net/browse/CLJ-2612&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2612&lt;/a&gt; witch fixes another issue in the same fn.</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10345/problems-with-s-union?show=10355#c10355</guid>
<pubDate>Wed, 17 Mar 2021 21:51:28 +0000</pubDate>
</item>
<item>
<title>Answered: Generating a function invokes the function</title>
<link>https://ask.clojure.org/index.php/10293/generating-a-function-invokes-the-function?show=10294#a10294</link>
<description>&lt;p&gt;After some extra investigation, I have understood that &lt;code&gt;s/conform*&lt;/code&gt; is invoked when generating the function via &lt;code&gt;s/valid?&lt;/code&gt; and that 21 is the default&lt;code&gt;*fspec-iterations*&lt;/code&gt; value.&lt;/p&gt;
&lt;p&gt;I was a bit surprised by the design choice of checking with full-instrumentation meaning with :args, :ret and :fn at function generation time, and only :args at function execution time.&lt;/p&gt;
&lt;p&gt;but after a second thought since every function is associated with a generator automatically, it is important to not silently generate a function that do not satisfy the  :fn property of the spec. Moreover since generating function purpose is to serve as stub checking only :args at execution time for correct error boundary checking is a good thing.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10293/generating-a-function-invokes-the-function?show=10294#a10294</guid>
<pubDate>Sun, 07 Mar 2021 03:27:44 +0000</pubDate>
</item>
<item>
<title>Answered: s/unform using spec containing (s/? (s/cat ,,,)) returns an invalid value (spec 1)</title>
<link>https://ask.clojure.org/index.php/9866/unform-using-spec-containing-cat-returns-invalid-value-spec?show=9869#a9869</link>
<description>&lt;p&gt;There are probably a couple things here. Regex forms parse sequential colls (importantly lists and vectors) but have no way to retain the original collection type and unform to the proper one. This is a generic problem and there are no easy solutions to it (if you consider all the aspects of conform, unform, and gen). We don&#039;t have plans to address in spec 1. In spec 2, we now have support for this with s/catv and s/cats which are type-specific variants.&lt;/p&gt;
&lt;p&gt;With respect to the (:as c), I think that is a known bug with trailing ? conforming, but it would take me a while to find the link.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9866/unform-using-spec-containing-cat-returns-invalid-value-spec?show=9869#a9869</guid>
<pubDate>Tue, 24 Nov 2020 22:41:51 +0000</pubDate>
</item>
<item>
<title>Answered: Using (s/or) without destructuring</title>
<link>https://ask.clojure.org/index.php/9844/using-s-or-without-destructuring?show=9845#a9845</link>
<description>&lt;p&gt;You should use &lt;code&gt;s/alt&lt;/code&gt; instead of &lt;code&gt;s/or&lt;/code&gt; in regex context:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/conform (s/cat :top (s/alt :nums (s/+ #{0 1 2 3 4})
                              :letters (s/+ #{\a \b \c \d})))
           [0 1 2 3])
=&amp;gt; {:top [:nums
          [0 1 2 3]]}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since &lt;code&gt;s/or&lt;/code&gt; is not a regex op, it will match the next item instead of a sequence:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(s/conform (s/cat :top (s/or :nums (s/+ #{0 1 2 3 4})
                              :letters (s/+ #{\a \b \c \d})))
           [[0 1 2 3]]) ;; note that it&#039;s wrapped vector
=&amp;gt; {:top [:nums
          [0 1 2 3]]}
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9844/using-s-or-without-destructuring?show=9845#a9845</guid>
<pubDate>Sun, 22 Nov 2020 20:52:15 +0000</pubDate>
</item>
<item>
<title>spec2 does not allow fn as retag in multi-spec</title>
<link>https://ask.clojure.org/index.php/9776/spec2-does-not-allow-fn-as-retag-in-multi-spec</link>
<description>&lt;p&gt;NB this is specifically a problem with &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/spec-alpha2&quot;&gt;spec-alpha2&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We&#039;ll use the example from the multi-spec example from the tutorial:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(spec2/def :event/type keyword?)
(spec2/def :event/timestamp int?)
(spec2/def :search/url string?)
(spec2/def :error/message string?)
(spec2/def :error/code int?)

(defmulti event-type :event/type)
(defmethod event-type :event/search [_]
  (spec2/keys :req [:event/type :event/timestamp :search/url]))
(defmethod event-type :event/error [_]
  (spec2/keys :req [:event/type :event/timestamp :error/message :error/code]))

(spec2/def :event/event (spec2/multi-spec event-type :event/type))
;;  ⇒ works as expected

(spec2/def :event/event (spec2/multi-spec event-type (fn [val tag] (assoc val :event/type tag))))
;; throws no impl of conform* for PersistentList

;; test case
(gen/sample (spec2/gen :event/event))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Essentially looks like spec2 can&#039;t handle retag functions yet, which makes it impossible to spec anything beyond simple maps, sadly.&lt;/p&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9776/spec2-does-not-allow-fn-as-retag-in-multi-spec</guid>
<pubDate>Tue, 10 Nov 2020 09:46:25 +0000</pubDate>
</item>
</channel>
</rss>