Hacker News new | ask | show | jobs
by TacticalCoder 22 days ago
> ... if the key is missing today you'll get nil as the value and since Clojure is a nil punning language it usually does sensible behaviour in your program

And that is still doable AIUI: they're optional checked keys. The doc describing them makes the distinction between required and non-required keys.

Arguably we already had those: I religiously use spec'ed maps in my Clojure since a great many years (and Clojure spec is still in alpha, but "alpha" in Clojure land basically means: "more stable and less likely to change than any feature in any other language" and I'm only slightly exaggerating here).

In my case I use good old defn-spec (form Orchestra but YMMV) instead of defn. And my maps are (partially) spec'ed, using spec'ed keys (as well as any other non-spec'ed key I feel like using). Sure it's only runtime checks but it's really great.

You get to both have the extensibility (you can for example add keys that don't exist yet later on without changing any of your specs) and you can specify which keys are required.

For there is such a thing as maps where you know that this and that key must always be there.

I don't think it's an issue to have optional checked keys. Especially not when you can mix both required and non-required keys in the same map.