<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Questions without answers in Spec</title>
<link>https://ask.clojure.org/index.php/unanswered/clojure/spec</link>
<description></description>
<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'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>Possibly revise s/merge behavior in spec.alpha2</title>
<link>https://ask.clojure.org/index.php/8844/possibly-revise-s-merge-behavior-in-spec-alpha2</link>
<description>&lt;p&gt;The example below shows that you can get generated values out of an s/merge using mult-specs that don't make sense with the intended spec.&lt;/p&gt;
&lt;p&gt;Looking at the implementation of the generator for s/merge each arg to s/merge gets generated individually, but it would be nice if they instead flowed through from right to left so things like multi-specs wouldn’t choose randomly from their dispatches.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;  (s/def :ent/id string?)

  (defmulti ent-multi-id :ent/id)
  (defmethod ent-multi-id :default [_] (s/keys))

  (defn maybe-retag-fn [retag-k]
    (fn [gen-v dispatch-tag]
      (if (= dispatch-tag :default)
        gen-v
        (assoc gen-v retag-k dispatch-tag))))

  (s/def ::ent (s/merge (s/multi-spec ent-multi-id (maybe-retag-fn :ent/id))
                        (s/keys :req [:ent/id])))

  (gen/sample (s/gen ::ent) 5)
  ;; =&amp;gt; ({:ent/id &quot;&quot;} {:ent/id &quot;w&quot;} {:ent/id &quot;&quot;} {:ent/id &quot;66&quot;} {:ent/id &quot;63v&quot;})

  (s/def :foo/id string?)

  (defmethod ent-multi-id &quot;foo&quot; [_]
    (s/keys :req [:foo/id]))

  (gen/sample (s/gen ::ent) 5)
  ;; =&amp;gt; ({:foo/id &quot;&quot;, :ent/id &quot;&quot;} {:foo/id &quot;6&quot;, :ent/id &quot;f&quot;} {:foo/id &quot;A&quot;, :ent/id &quot;W&quot;} {:foo/id &quot;L&quot;, :ent/id &quot;nd&quot;} {:ent/id &quot;H&quot;})
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Spec</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8844/possibly-revise-s-merge-behavior-in-spec-alpha2</guid>
<pubDate>Thu, 07 Nov 2019 17:31:28 +0000</pubDate>
</item>
</channel>
</rss>