[Bug?] Spec: spec/? not working?

85 views
Skip to first unread message

Torsten Anders

unread,
Jul 20, 2016, 5:59:35 PM7/20/16
to Clojure
Dear all,

I have some problems using clojure.spec: ? does not work as I would expect it. Instead of specifying an optional value, it seems that such values are never permitted, and instead the next value is always matched. Please see the short example demonstration below. BTW, * seems to cause the same problem.

What am I missing?


(ns test-ns
  (:require [clojure.spec :as spec]))

(spec/def ::test-spec (spec/cat :symbol symbol?
                                :optional-string (spec/? string?)
                                :int int?))
(spec/valid? ::test-spec '[test 42]) ; -> true
(spec/valid? ::test-spec '[test "my string" 42]) ; -> false

(spec/explain ::test-spec '[test "my string" 42])
;; In: [1] val: "my string" fails spec: :clojure2minizinc.core/test-spec at: [:int] predicate: int?


Best,
Torsten

Sean Corfield

unread,
Jul 20, 2016, 8:25:51 PM7/20/16
to Clojure Mailing List

Your code works for me as expected on 1.9.0 Alpha 10. What version are you using?

 

Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Torsten Anders

unread,
Jul 21, 2016, 4:00:29 AM7/21/16
to Clojure
Thanks a lot for testing that. I am also using the same 1.9.0 Alpha 10, should have said so.

I found the error, which was in my code.

Best,
Torsten
Reply all
Reply to author
Forward
0 new messages