Fork me on GitHub
#clojure-spec
<
2016-08-28
>
lvh14:08:45

I’m trying to use regex ops and running into some problems. I have two data structures naturally represented by a regex, the main one is of the shape: a*c, in my map data structure in order to get the item at that location, the get-in path is something like (ab)*c — it seems that the problem is that nested regex operators “merge”; so now for a fn that takes a*c and returns (ab)*c, I can’t specify its :args as (s/cat :a ::a) — does that make sense?

lvh14:08:19

Looks like that’s intentional; found it in the guide 🙂 > When regex ops are combined, they describe a single sequence. If you need to spec a nested sequential collection, you must use an explicit call to spec to start a new nested regex context. For example to describe a sequence like [:names ["a" "b"] :nums [1 2 3]], you need nested regular expressions to describe the inner sequential data:

lvh14:08:53

Makes sense — you’d want to be able to parse both, and break them out 🙂

sveri16:08:22

Hi, how do I spec functions with optional arguments?

lvh20:08:51

sveri: usually you use regex ops to describe the args as they would be given to apply

lvh20:08:58

so .e.g you can use spec/?

potetm22:08:18

How would you spec 2 arguments where one arg's validity depends on the other arg.

potetm22:08:12

For example: (fn [i-am-a-map i-am-a-key-in-the-map] ...)

gfredericks22:08:10

potetm: you can use s/and

potetm22:08:14

@gfredericks perfect; just figured that out 🙂