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

0 votes
ago in Syntax and reader by
edited ago by

I'm trying Clojure 1.13.0-alpha4. I have a problem with :keys! and :or. The first example works as expected with the old :keys. The second example gives me a syntax error when I switch to the new :keys!. The thirds example works when I avoid the required key in the defaults.

 (let [{:keys [a] :or {:a 1}} {:a 2}] a)
 ;=> 2
    
(let [{:keys! [a] :or {:a 1}} {:a 2}] a)
Syntax error macroexpanding let at (REPL:1:1).
Can't supply default value for required key: :a

(let [{:keys! [a] :or {:b 1}} {:a 2}] a)
;=> 2

1 Answer

0 votes
ago by
selected ago by
 
Best answer

Yes, this is as expected.

Note that pre-1.13, :or was a map of binding (unadorned symbol) to default value to be used if a bound key was missing. Any other key type had no meaning and was ignored. In 1.13, :or may contain literal keys that will be added to the :defaults map or be used to fill in the :select map (they have no other use).

1) No :defaults or :select, so :a is just ignored.

2) a is now bound and thus :a is required. Because of this, there is no possibility to use :a from :or in :defaults or :select, so this is now an error.

3) Again, :b is not needed for :defaults or :select, so ignored (really same as #1).

ago by
So it's protecting me from an ineffectual :or, not a logical error.  I had interpreted the error message as saying that the Clojure compiler couldn't do something because of the key.  Actually, the message is telling me that *I* can't do that.
ago by
Yes, exactly :)
ago by
Maybe we should protect you from the ineffectual thing too, but I'll let Rich decide that.
...