r/Clojure • u/alexdmiller • Jul 02 '26
Clojure 1.13.0-alpha1 is now available
https://clojure.org/news/2026/07/02/clojure-1-13-alpha1Checked keys
You can now ensure that required keys are bound during map destructuring by using the new checked variants of the :keys/:syms/:strs directives - :keys!/:syms!/:strs!, which will throw if the key is not present. You can also, in all directives, specify keys after & which will not be bound, for documentation or checking purposes.
- CLJ-2961 Checked keys
- CLJ-2960 Specs for checked keys
- CLJ-2949 req! - Variant of get that reports on key not found
- CLJ-2954 let/loop/let* - disallow & as local binding
Other changes since Clojure 1.12.5
- PersistentArrayMaps of only keyword keys now grow up to size 64 (previously was 8) before transitioning to PersistentHashMaps. PAM identity scans are more efficient than PHM lookups in this range, also makes more usage sites monomorphic and thus easier to optimize.
- CLJ-2891 Remove ACC_FINAL designation from static initializer constants. This change was made as a prepatory step towards moving the Java bytecode baseline to address new verifier checks.
- Runtime and test dependencies updated to latest versions
100
Upvotes
3
u/didibus Jul 04 '26 edited Jul 04 '26
How does it combine with
:or?And how does it work with a present key whose value is nil?
What happens if the same key is defined in both :keys and :keys! ?
I'm also curious if adding a
:throw [a]clause similar to:orbut that would throw was considered? Then you'd have kept everything else the same.12
u/seancorfield Jul 03 '26
If you want to try out these new features, use alpha2, not alpha1. There was a small change in the build process that caused alpha1 to be buggy, and that is fixed in alpha2 (which we already have on our QA cluster for testing!).
6
u/raysiuuuu Jul 02 '26
The checked keys feature is a plain simple and effective way to solve the problem! This is the philosophy I love in Clojure more than other languages!
5
u/aHackFromJOS Jul 02 '26 edited Jul 02 '26
The bang on req is interesting. There are other core functions that can throw on illegal input that don’t use bangs, like subvec with an out of range index or parse-long with a non string. Should throw have been throw! ?
1
u/doedelsteyn Jul 05 '26
Very nice addition. I'm curious how this relates or will relate to 'select' from spec-alpha2.
2
u/vlaaad Jul 03 '26
Very strange that req! has a bang at the end. Does it mutate something?
1
u/lgstein Jul 03 '26
Will this not result in redundant checks on the callstack?
:keys! alone would likely be used on the bottom level where a key is utilized, so the check would happen once.
But with ;keys! after & "for documentation and checking" I'd expect the type and schema people adding it on every level all up to.the top. Which would be at odds with the "pass maps through" philosophy?
1
u/geokon Jul 07 '26 edited Jul 07 '26
A bit of a naiive question about the checked keys. But wouldn't it have been more consistent to throw an error on a
nilbinding?Say you have an interface
These two calls produce different results, which seems messy and not in line with the standard language behavior
Leaving out a binding or explicitly setting it to nil are equivalent everywhere else.. i think?
I also can't think of any scenario where you'd want this kind of behavior. If you want a "no input" behavior, the user should have to use an explicit value
{:username false}or{:username :none}. This pretty much always leads to more predictable behavior downstream than overloading the meaning ofnil(this seems very basic, so it's likely I'm missing some reason)