<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged spec-tools</title>
<link>https://ask.clojure.org/index.php/tag/spec-tools</link>
<description>Powered by Question2Answer</description>
<item>
<title>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</link>
<description>&lt;p&gt;When using spec-tools (&lt;code&gt;metosin/spec-tools {:mvn/version &quot;0.10.5&quot;}&lt;/code&gt;) to spec a list of values, result spec produces inconsistent results when validated against in s/valid? and s/explain.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Minimal example&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(ns case
  (:require [spec-tools.data-spec :as ds]
            [clojure.spec.alpha :as s]))

(def invalid-data {:cards (list 66)})

(def valid-data {:cards [66]})

(def cards
  {:cards [int?]})

(defn do-stuff [data]
  (if (s/valid? (ds/spec ::sp cards) data)
    (println &quot;Conforms to spec according to &#039;valid?&#039;&quot;)
    (println &quot;Does not conform to spec according to &#039;valid?&#039;&quot;))
  (if (s/explain-data (ds/spec ::sp cards) data)
    (println &quot;Does not conform to spec according to &#039;explain-data&#039;&quot;)
    (println &quot;Conforms to spec according to &#039;explain-data&#039;&quot;)))

(comment
  (do-stuff invalid-data)
  (do-stuff valid-data))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For some reason s/valid? and s/explain produce different result when a list is used, but same when a vector is used. When I tried to reproduce this issue with spec created directly with clojure.spec.alpha, everything was fine, so it seems the problem is with spec-tools. Nevertheless, it should produce same results in all validation functions, I guess&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</guid>
<pubDate>Wed, 24 May 2023 14:41:51 +0000</pubDate>
</item>
</channel>
</rss>