clojure-dev 2026-07-30

The new destructuring with & is like a pre-condition on the shape of the map. As there is a runtime cost for checking the keys. has there been any thought of putting the check behind an **assert** guard?

Reading the dynamic var isn't free either? ;)

Please, no. I raised the specter of assert when Alex first talked about :keys! etc in the Clojure Dev Talk, and the core team reassured folks that, no, that would not be based on assert, it would be regular Exception types (not Error types).

An Exception is definitely better than an Error, but that doesn't stop it from the check being guarded at compile time by **assert**.

I'd be very strongly against that. My objection to assert is two-fold: it can be turned off (bad); it uses a Throwable subtype that the Java docs are clear "should not be caught" and therefore programs should not try to recover from (bad).

Alex Miller (Clojure team) 2026-07-30T14:27:36.993109Z

just to be pedantic, guarding by *assert* (or other flag) does not necessarily mean that an assertion exception would be thrown, those are two different parts of the problem

Alex Miller (Clojure team) 2026-07-30T14:28:34.371489Z

I think hugo was primarily asking for the guard, not for assert

👍 2
Alex Miller (Clojure team) 2026-07-30T14:29:13.685609Z

will discuss

Is there anything in Clojure that is currently guarded by *assert* that does not lead to something that throws an Error?

(genuine Q since I don't know the answer without trawling through the source code)

Alex Miller (Clojure team) 2026-07-30T16:30:11.615349Z

@hugod I think right now, we're not going to do this - you can just switch to :keys if you don't want the checking. but we may look at it again later.

Alex Miller (Clojure team) 2026-07-30T16:31:24.094799Z

@seancorfield regardless, we are highly unlikely to use assert flags or impl stuff if this or related were put under a runtime flag

👍🏻 1
1

Dev time with asserts and production without is a real use case. I can understand not doing it now though (and preferring a different flag). Thanks for considering it.

> Dev time with asserts and production without is a real use case. As you probably guessed, I think this is a terrible anti-pattern, and the wrong way to think about these sorts of checks in general. But I know that's a minority view point 🙂

➕ 1

I would argue against doing it general, but I think there are reasonable justifications for doing so in some cases.

I think there are reasonable justifications for doing so in some cases
IMO there are and important ones related to performance. If you can add checks you know are only dev time you can add many kinds of crazy checks without having to think about perf impact on prod.

@hugod have definitely considered and decided against for req! specifically. But post & required keys is still a candidate for a runtime toggle. As @alexmiller said, unlikely on its own. But there are more features which absolutely will have a toggle and this might piggyback on that.

👍 3