Welcome! Please see the About page for a little more info on how this works.

0 votes
in Syntax and reader by

It's a rather frequent question where somebody gets a syntax error when trying to use something like {:keys [a b ...] :or {b a}}. The most recent instance: https://clojurians.slack.com/archives/C03S1KBA2/p1742549907988549

The error is as user-unfriendly as it gets and the behavior is also counter-intuitive if you don't happen to know the insides of destructuring and maps.

Perhaps it would make sense to alter the destructuring impl for when the default value in :or is not a primitive. So instead of being expanded to b (get map__1 :b a) it's expanded to b (get map__1 :b ::not-found) with a subsequent rebinding to b (if (identical? b ::not-found) a b) after all the other keys have already been extracted.

1 Answer

0 votes
ago by

The intent of :or is to provide a default value for missing values, not to provide an arbitrary expression over things that are in the process of being bound by the destructuring itself. This is not a feature we want to support.

...