clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
nullptr 2020-01-15T18:54:48.056Z

i have a dumb spec question that unfortunately is in the "difficult to google" category - say i had a sequence with the following structure: [1 "a" 2 "b" "c" 0 3 "d" "e" "f"] the pattern here is a number which indicates how many following items there are directly in the sequence -- i adjusted spacing above to hopefully make that clearer this is of crouse trivial to express if the following items are in another sequence, but scanning the docs i can't see a way to spec the flat version of this -- note that this isn't motivated by any important use case, more just part of me trying to learn spec so feel free to treat this as pure curiosity

alexmiller 2020-01-15T19:16:19.056400Z

regex specs combine to spec one flat sequence

alexmiller 2020-01-15T19:20:05.057800Z

so you could do something like (s/* (s/& (s/cat :c nat-int? :s (s/* string?)) #(= (:c %) (count (:s %)))))

💡 1
nullptr 2020-01-15T19:23:18.059100Z

thanks! that is extremely straightforward -- i feel like i had something similar but surely missed something basic and made a wrong assumption. will compare and learn -- thanks again.

alexmiller 2020-01-15T19:24:28.059400Z

it's very important to use s/&, not s/and there

alexmiller 2020-01-15T19:24:49.060200Z

s/and is not a regex spec and will expect a new nested collection boundary

1
nullptr 2020-01-15T19:24:52.060400Z

yeah i had the & but i think i had a surrounding cat there that was throwing it all off