Fork me on GitHub

Is it possible to define a spec of a sequence of values where some values are required, some are optional, and the order doesn’t matter? For example, a sequence that requires 1 string, 1 boolean, 1 number, and an optional set of two-digit numbers?

(require clojure.spec.alpha :as s)

(s/valid? ::toy-ex ["hi" 5 true]) ;=> true
(s/valid? ::toy-ex ["hi" 5 true 25]) ;=> true
(s/valid? ::toy-ex ["hi" 25]) ;=> false

(s/valid? ::toy-ex [true "hi" 5]) ;=> true
(s/valid? ::toy-ex [25 5 true "hi"]) ;=> true
(s/valid? ::toy-ex [25 5 true "hi" false]) ;=> false


real-world example is I am taking in ical entries split on the line. So they are a sequence of strings each matching a regex, and some are required and some are optional, but there is no guaranteed or required order to the lines. The closest I have is:

(require clojure.spec.alpha :as s)
;...defining all the various regexes i used below...

(s/def :vevent/vevent-coll
   (s/* (s/alt ::summary :vevent/summary
               ::dtstart :vevent/dtstart
               ::dtend :vevent/dtend
               ::uid :vevent/uid))
   (s/* (s/alt ::location :vevent/location
               ::description :vevent/description
               ::description-text :vevent/description-text
               :created :vevent/created
               ::ignorable string?))))
This works well enough when conforming a valid ical sequence, but it also allows invalid ones too easily.


Spec provides a super set of the regex operators, so if conceptually it could be matched by a regex, then spec can match it


In a regex, the operator you are looking for is '?' so just look at the docs for the spec namespace and find the spec combinator that does that


thank you!

Michał Frątczak10:12:44

Hey all. Is it worth to try clojure on windows? And if yes, is this link best choice to start and up-to-date ?

Michał Frątczak11:12:19

Actually I am looking for a best frictionless setup to try clojure on my windows laptop (with VS code optionally)


I think WSL + is still your best option on Windows

❤️ 2

There is also #CFN4QDHPS if you get stuck.


If someone is adept at Windows and Powershell, then installing Clojure should be okay, but probably not as smooth as Unix (Linux/Mac). Using clojure on Windows should work okay, although its the little things like escaping command line arguments (e.g. for Clojure CLI clojure.exec method) that can be a little fiddly. Consensus seems to be that WSL is the smoothest approach for windows, especially if its a recent version of Windows. There seems to also be advantage if using VS Code as the editor of choice (it can tap into WSL a little more smoothly) On older versions of Windows or if WSL is not available, then there is

Michał Frątczak15:12:49

I will try wsl way (win10)


Recommend WSL also

Bob B18:12:06

while it's "non-standard", I also find deps.clj (<>) quite nice for windows - if you're doing most things in VSC, then Calva will handle a lot of the things fairly independently of the OS (invoking java directly)

Michał Frątczak18:12:00

I now have vscode/wsl/calva setup running and I go through calva's "getting started REPL". So far so good !

येसुदीप मंगलापिल्ली Yesudeep Mangalapilly06:01:53

If I get my clojure(script) rules working with bazel, all you'll need is and the following irrespective of your operating system or shell. You won't need any installer scripts either. Just install bazel and add definitions (resembling your module dependency graph) like the following in your build file (bazel fetches clojure(script) and your dependencies automagically, and runs your code):

# MODULE.bazel

bazel_dep(name="rules_clojure", version="...")

# ... some more boilerplate ...
# BUILD.bazel

# ...

    name = "core_clojure_lib",
    srcs = [
    deps = [

    name = "core_clojure_test",
    srcs = [
    deps = [

    name = "hello_world_clojure",
    ns = "tests.hello-world.core",
    deps = [

    name = "hello_world_clojure_repl",
    ns = "tests.hello-world.core",
    deps = [
Hopefully, I can get this thing and (build file generator) integration working so you don't even have to write the build files by hand. fingers crossed

येसुदीप मंगलापिल्ली Yesudeep Mangalapilly06:01:43

And running tests looks like this To answer your question "Is it worth to try clojure on windows?" I'd say certainly. As you can see I've almost gotten it to work without too many hiccups using both wsl and powershell. (Msys2 works too btw)