This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-11
Channels
- # beginners (132)
- # boot (2)
- # cider (17)
- # cljs-dev (6)
- # cljsrn (24)
- # clojure (134)
- # clojure-austin (2)
- # clojure-dusseldorf (11)
- # clojure-france (1)
- # clojure-greece (27)
- # clojure-italy (17)
- # clojure-madison (1)
- # clojure-russia (31)
- # clojure-serbia (1)
- # clojure-sg (2)
- # clojure-spec (30)
- # clojure-uk (66)
- # clojurescript (73)
- # core-async (2)
- # cursive (8)
- # data-science (2)
- # datomic (23)
- # dirac (8)
- # emacs (18)
- # gsoc (1)
- # hoplon (36)
- # immutant (26)
- # leiningen (6)
- # off-topic (21)
- # om (19)
- # onyx (6)
- # other-languages (1)
- # pedestal (3)
- # proton (2)
- # random (1)
- # re-frame (1)
- # reagent (2)
- # remote-jobs (2)
- # ring-swagger (8)
- # rum (21)
- # slack-help (1)
- # spacemacs (4)
- # specter (16)
- # untangled (6)
Can you please point me what I’m doing wrong in example below:
(defn command [m] 1)
(s/fdef command
:args (s/cat :n int?)
:ret string?)
(command "ff") ;; => 1
It works and is not failing with exceptionrmuslimov: Are you instrumenting your function? https://clojure.org/guides/spec#_instrumentation_and_testing
The :ret spec is checked only by stest/check
You can also use Orchestra to instrument your spec return values: https://github.com/jeaye/orchestra/
One more newbie question about spec. here as example
{:email1 ""
:email2 ""
:email3 ""
:email4 ""
:email5 ""
:data 1112}
Here is spec I wrote, anyway to make it shorter?
(s/def ::email1 string?)
(s/def ::email2 string?)
(s/def ::email3 string?)
(s/def ::email4 string?)
(s/def ::email5 string?)
(s/def ::data int?)
(s/def ::item
(s/keys :req-un [::email1 ::email2 ::email3 ::email4 ::email5 ::data]))
yep, fixed. but question remain the same. Why spec is longer than data? is it supposed to be like that? Or it’s my un-optimized solution?
it’s supposed to be like that.
Would it be dangerous for a user to create a macro for that? like (sdef-each seq-of-keys string?)
no, macro as you like
rgr. so, @U0AR40HJ6, it's possible, bit it's definitely not a newbie/beginner level answer, if you're new to the language in general.
@U050PJ2EU I can do a macro, was just wondering if there exist any proper way to that. thanks!
No prob. Might want to consider using the long form though, from a user/documentation perspective.
If core comes out with such a function in the future, then you can rely on your downstream users to know what you're talking about (if that's a factor for you)
not going to add that to core
right, so if you are making a library you expect to be consumed by others, remember that spec is also intended to be used for documentation.
if you’re just wrapping calls to s/def
, I don’t see how that matters
there will be no difference between doing it explicitly or doing it in a macro?
the macro would presumably just unroll to the same set of calls
@U064X3EF3 so any documentation functions that operate on sources will probably operate post macro-expansion?
doc functions don’t use the sources for specs
docs look up the specs in the registry