<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged 1.13</title>
<link>https://ask.clojure.org/index.php/tag/1.13</link>
<description></description>
<item>
<title>Checked behavior in 1.13 destructuring outside of `:keys!` like directives</title>
<link>https://ask.clojure.org/index.php/15244/checked-behavior-destructuring-outside-keys-like-directives</link>
<description>&lt;p&gt;With 1.13 Clojure introduces new directives to associative destructuring. Is there a way to get the checked behavior (throw when the key isn't present) on keys destructured without using &lt;code&gt;:keys!&lt;/code&gt; like directives ?&lt;/p&gt;
&lt;p&gt;I like being able to have vars holding keywords. It allows me to document them and it's also convenient in the case of typos since I tend to catch them sooner in var names rather than in keywords.&lt;/p&gt;
&lt;p&gt;For instance consider the follow example :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def foo
   &quot;My nice doc for foo.&quot;
   ::foo)

(def bar
  &quot;My nice doc for bar.&quot;
  ::foo)

(def example-map {foo :value})

;; How do I say here that I want foo and bar to be present without a `:keys!` directive ?
(let [{foo-binding foo
            bar-binding bar} example-map]
  [foo-binding bar-binding])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If there isn't a way, would a &lt;code&gt;:checked&lt;/code&gt; directive be a good idea :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; This would throw, `bar` is absent from `example map`
(let [{:checked {foo-binding foo
                   bar-binding bar}} example-map]
  [foo-binding bar-binding])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code&gt;:&amp;amp;&lt;/code&gt; directive meaning checked and unbound could also be possible:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;;; This would throw, `bar` is absent from `example map` but it wouldn't be bound
(let [{:checked {foo-binding foo}
       :&amp;amp; {bar-binding bar}} example-map]
   [foo-binding])
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Did I miss that feature somehow? If not what do you think about &lt;code&gt;:checked&lt;/code&gt; and&lt;br&gt;
&lt;code&gt;:&amp;amp;&lt;/code&gt; directives ?&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;
&lt;p&gt;Edit:&lt;/p&gt;
&lt;p&gt;I just thought of another use case for a &lt;code&gt;:checked&lt;/code&gt; like directive. Directive-less destructuring allows for binding names different from keyword names. We can do :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [{id1 :a/id
       id2 :b/id} some-map]
  ...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Whereas:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(let [{:keys! [:a/id :b/id]} some-map]
   ...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;does not let you have different bindings for keyword sharing the same name.&lt;/p&gt;
&lt;p&gt;Leaving aside the var holding keywords pattern that may be a bad idea. Would the binding of namespace qualified keywords sharing the same name be a valid argument to consider a &lt;code&gt;:checked&lt;/code&gt; like directive?&lt;/p&gt;
</description>
<category>Clojure</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15244/checked-behavior-destructuring-outside-keys-like-directives</guid>
<pubDate>Mon, 12 Oct 2026 14:12:23 +0000</pubDate>
</item>
</channel>
</rss>