Fork me on GitHub
#clojure-spec
<
2017-01-02
>
roelof09:01:53

I have these specs :

; specs for validatimg input to find rhe ids
(s/def ::artObject (s/keys :req-un [::objectNumber]))
(s/def ::artObjects (s/coll-of ::artObject))
(s/def ::body (s/keys :req-un [::artObjects]))
(s/def ::response (s/keys :req-un [::body]))
 

roelof09:01:23

now I have to extend them for another call with some things

roelof09:01:05

Can I just make a copy with it and extend it and named all the keywords then ::data-response

roelof09:01:16

or is there a better way ?

luxbock11:01:29

so I'm working on my idea of writing a defn-like macro that infers specs from the (extended) destructuring syntax of the argument vector

luxbock11:01:52

and I was thinking that in the case of a simple case of {:keys [(foo int?)]}, which of course means that the passed map contains an optional unqualified key of :foo which is an int

luxbock11:01:01

I need to define the spec for :foo. would it be a terrible idea to just use a randomly generated ns for that such as :foo1235/foo?

luxbock11:01:19

i.e. the argument vector [{:keys [(foo int?)]}] expands to (s/def :foo1235/foo int?) + (s/cat :m (s/keys :opt-un [:foo1235/foo]))

luxbock11:01:12

I don't want to end up in a situation where my defn-macro ends up overwriting specs for situations where multiple functions accept maps that contain simple-keywords that can contain different types of values

roelof16:01:39

nobody who can help me with this one

sveri17:01:11

@roelof It is hard to tell what exactly you want to do. At least for me. I am pretty sure you can do what you want, but if you need help I guess you need to be more specific and provide some examples.

seancorfield17:01:58

Also, it seems to be the same question you’ve asked several times now — and it has been answered in the #beginners channel...

seancorfield17:01:59

I have answered it at least twice now in the #beginners channel and you’ve had input from other people there.

fadrian17:01:23

I'm doing my best to understand spec. I'm working through a cards example, using my own representation of a card. I've defined my specs as follows:

fadrian17:01:42

According to the spec spec, my definition for cards should be checking for correct conformance for ::suit and ::rank. But (s/conform ::card "1m") returns "1m", not an invalid as I expect. What's happening here?

gfredericks18:01:28

@luxbock I'd use the current ns plus an extra random segment as the namespace

seancorfield18:01:09

@fadrian suits should be a set, not a map.