Hi to anyone reading,
I'm trying to understand a difference in behavior when using clojure.spec/conform on two different regex ops: + and *.
They often conform the same when there is at least one item, but not always.
One small case I've found is:
(s/def ::evens-or-odds (s/alt :evens (s/+ even?)
:odds (s/+ odd?)))
(defn conform-test [nums]
(let [star (s/conform (s/* ::evens-or-odds) nums)
plus (s/conform (s/+ ::evens-or-odds) nums)]
[(= star plus)
star
plus]))
(conform-test [1 2 3]) =>
[true
[[:odds [1]] [:evens [2]] [:odds [3]]]
[[:odds [1]] [:evens [2]] [:odds [3]]]]
(conform-test [1 2 2]) =>
[false
[[:odds [1]] [:evens [2 2]]]
[[:odds [1]] [[:evens [2 2]]]]]
(conform-test [1 2 2 3]) =>
[false
[[:odds [1]] [:evens [2 2]] [:odds [3]]]
[[:odds [1]] [[:evens [2 2]] [:odds [3]]]]]
They conform the same for the first, but on the second and third, the + regex wraps all but the first group in a vector. I believe it has something to do with nested regex ops, but I haven't figured out the pattern.
Same conform value:
[1 2]
[1 2 3]
[1 1 2 3]
Different conform values:
[1 2 2]
[1 2 2 3]
[1 2 3 3]
I appreciate your time and any insight or ideas about why these sets of cases conform differently.
Thanks,
Cole