beginners 2026-07-10

Am I correct in understanding that :opt keys in a :keys spec are basically just informational? Given that all keys are validated if they have associated specs and maps are open, it seems that (technically) every key is an optional key

Is it considered an undefined behavior? Or is it the actual guarantee?

Like could we expect the behavior to change in the future and be an implementation detail?

Alex Miller (Clojure team) 2026-07-11T23:58:11.770379Z

For what?

I assume guarantee since the spec guide on the website says: > When conformance is checked on a map, it does two things - checking that the required attributes are included, and checking that every registered key has a conforming value. We’ll see later where optional attributes can be useful. Also note that ALL attributes are checked via keys, not just those listed in the :req and :opt keys. Thus a bare (s/keys) is valid and will check all attributes of a map without checking which keys are required or optional.

👍 1

That s/keys loops over all keys to validate their values, and not just the ones declared in req and opt.

Interesting, I never noticed you could just define a bare s/keys to validate values of specced keys.

Alex Miller (Clojure team) 2026-07-12T01:07:40.457679Z

it's guaranteed and discussed in the docstring

👍 1
Alex Miller (Clojure team) 2026-07-10T00:21:13.710069Z

They are also used in the generator

👍🏻 1

Normally you also define specs for the values. Then you need :opt .

👎🏼 1
Alex Miller (Clojure team) 2026-07-10T04:17:56.148719Z

Value specs are checked for all keys, regardless of whether in req or opt