Fork me on GitHub

Hi, I’ve read the spec guide and couldn’t really come up with the correct way to do the following; Apologies if i had missed something. I am looking to define a spec for a ::paragraph that consists of “::words” , “::space(s)” , and “less often” ::punctuation. It (of course) does not need to be grammatically correct. It seems like i need something like s/cat however i want the results to be not a vec but a larger string (that consists of smaller “spec” strings...“). I’m interested in having a spec for ::paragraph as well as a generator to play with a natural language processing app i’m working on. Any tips appreciated,


I managed to do something like that by using conformer to tokenize the string first. E.g.:

(s/and string?
       (s/conformer #(str/split % #",") #(str/join "," %))
       (s/cat ...))
But it won’t be as fast as a real parser.


Typed that on my phone from memory, so apologies if I got things incorrect.

Alex Miller (Clojure team)15:08:26

I think you’re probably asking for more out of spec than it is designed to provide


ok, that makes sense. thanks, i’ll come up with something.


Is there a version (in some library, etc) of s/keys that allows me do manipulate the spec definition before proceeding? My current pattern for that is:

(eval `(spec/keys :req ~(conj dependencies ::foo-options)))
...Generally it works fine, but now my needs also include clojurescript, so I can't use eval

Alex Miller (Clojure team)21:08:42

I don't think there is an easy pattern for it in spec 1. CLJ-2112 has a sketch of specs for specs which lets you conform, modify then unform, but it's pretty cumbersome due to the structure of s/keys.

Alex Miller (Clojure team)21:08:28

spec 2 has several ways to do this and a new symbolic map form in work in particular


Appreciate the confirmation, thanks!


what would the regex to match "one or more forward slashes" be? #"\/+" doesn't seem to compile or work


also tried several other permutations


this seems to have worked: (js/RegExp. "\\/+")


but pretty sure #"\\/+" did not


user=> (re-seq #"\/+" "///////asd////")
("///////" "////")
It definetely compiles.