Skip to content

Commit 8a5e31a

Browse files
committed
regenerate site
1 parent 164a2c5 commit 8a5e31a

File tree

6 files changed

+64
-48
lines changed

6 files changed

+64
-48
lines changed

articles/language/functions/index.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,26 @@ <h2>Language: Functions</h2>
190190
[{:keys [currency amount]}]
191191
currency)
192192
</code></pre><p>The example above assumes that map keys will be keywords and we are interested in two values: <code>currency</code>
193-
and <code>amount</code>. The same can be done for strings:</p><pre><code class="clojure">(defn currency-of
193+
and <code>:amount</code>. The same can be done for strings:</p><pre><code class="clojure">(defn currency-of
194194
[{:strs [currency amount]}]
195195
currency)
196196
</code></pre><p>and symbols:</p><pre><code class="clojure">(defn currency-of
197197
[{:syms [currency amount]}]
198198
currency)
199199
</code></pre><p>In practice, keywords are very commonly used for map keys so destructuring with <code>{:keys [...]}</code> is very common
200-
as well.</p><p>Map destructuring also lets us specify default values for keys that may be missing:</p><pre><code class="clojure">(defn currency-of
200+
as well.</p><p>If you want to destructure a map that has namespaced keys, you can either
201+
specify the prefix on each name in the binding or as a prefix on <code>:keys</code> itself:</p><pre><code class="clojure">;; instead of {:currency "GBP" :amount 95.99} let's assume we have namespaced
202+
;; keys: {:invoice/currency "GBP" :invoice/amount 95.99}
203+
(defn currency-of
204+
[{:keys [invoice/currency invoice/amount]}] ; prefixed names
205+
currency) ; bind to unprefixed symbols
206+
207+
;; or
208+
209+
(defn currency-of
210+
[{:invoice/keys [currency amount]}] ; prefixed :keys
211+
currency) ; bind to unprefixed symbols
212+
</code></pre><p>Map destructuring also lets us specify default values for keys that may be missing:</p><pre><code class="clojure">(defn currency-of
201213
[{:keys [currency amount] :or {currency :gbp}}]
202214
currency)
203215
</code></pre><p>This is very commonly used for implementing functions that take "extra options" (faking named arguments support).</p><p>Just like with positional destructuring, map destructuring works exactly the same way for let bindings:</p><pre><code class="klipse-clojure nohighlight">(let [money {:currency :gbp :amount 10}

articles/tutorials/getting_started/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ <h2>Getting Started</h2>
9898
repositories) without needing JAR files to be built and deployed.</p><p>Since the release of the official Clojure CLI, usage of Leiningen has dropped
9999
as the community adopted the new CLI and associated libraries such as
100100
<code>tools.deps</code> and <code>tools.build</code>.
101-
<em>[See <a href="https://clojure.org/news/2022/06/02/state-of-clojure-2022">State of Clojure 2022 Survey Results</a>]</em></p><p><strong>Too Much Information! What Should I Use?</strong></p><p>As noted above, if you're following a book or tutorial that uses Leiningen,
101+
<em>[See <a href="https://clojure.org/news/2022/06/02/state-of-clojure-2022">State of Clojure 2022 Survey Results</a> -- and a year later the CLI usage exceeded 70% while Leiningen had dropped to around 60%]</em></p><p><strong>Too Much Information! What Should I Use?</strong></p><p>As noted above, if you're following a book or tutorial that uses Leiningen,
102102
or working with a project that uses Leiningen, then keep using Leiningen.</p><p>If you're following a book or tutorial that uses the newer CLI, or working
103103
with a project that uses it, then keep using the Clojure CLI and associated
104104
libraries.</p><p>If you're starting from scratch, learning the Clojure CLI is probably a

articles/tutorials/introduction/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,13 @@ <h2>Introduction to Clojure</h2>
148148
you want to include a double-quote mark in a string, backslash-escape
149149
it.</p><pre><code class="clojure">#"^foo\d?$" ; A regular expression.
150150
:foo ; A keyword.
151+
:foo/bar ; A namespaced keyword.
151152
</code></pre><p>We'll have more to say about <a href="#regular-expressions">regular
152153
expressions</a> later on.</p><p>Keywords are just scalars that evaluate to themselves and are useful
153154
where in other languages you might use little strings as identifiers
154155
(for example, as the keys in a hashmap). More about keywords in the
155-
next section (<a href="#data-structures">Data Structures</a>).</p><pre><code class="clojure">'foo ; A symbol.
156+
next section (<a href="#data-structures">Data Structures</a>).</p><pre><code class="clojure">'foo ; A symbol.
157+
'foo/bar ; A namespaced symbol.
156158
</code></pre><p>A <em>symbol</em> is an object that represents the <em>name</em> of something. The
157159
single quote mark is there to keep Clojure from trying to figure out
158160
to what the symbol refers (the quote isn't part of the identifier of
@@ -172,8 +174,10 @@ <h2>Introduction to Clojure</h2>
172174
[1 :two "three"] ; Put anything into them you like.
173175
{:a 1 :b 2} ; A hashmap (or just "map", for short).
174176
</code></pre><p>A hashmap is your typical hash/dictionary data structure. In the above
175-
example, the keys are :a and :b, and the values are 1 and 2. One key-value
176-
pair in a map is called an <em>entry</em>.</p><p>Although it's most common to use keywords (as shown above) for hashmap
177+
example, the keys are <code>:a</code> and <code>:b</code>, and the values are 1 and 2. One key-value
178+
pair in a map is called an <em>entry</em>.</p><p>Using namespaced keywords as keys is a common practice in Clojure applications,
179+
as it provides more context to the key and helps avoid key collisions:</p><pre><code class="clojure">{:customer/id 123 :invoice/id "INV-456" :invoice/total 95.99}
180+
</code></pre><blockquote><p>Note: if you have a hashmap where all the keys have the same namespace prefix, such as <code>{:invoice/id "INV-456" :invoice/total 95.99}</code>, the REPL will print it using a shorthand syntax, where the prefix is shown in front of the hashmap and the keys are shown without the prefix: <code>#:invoice{:id "INV-456", :total 95.99}</code>. This is just a shorthand syntax for printing the hashmap and doesn't affect how you use the hashmap in your code.</p></blockquote><p>Although it's most common to use keywords (as shown above) for hashmap
177181
keys, you can use any values you like for the keys as well as the
178182
values.</p><pre><code class="clojure">#{:a :b :c} ; A set (unordered, and contains no duplicates).
179183
'(1 2 3) ; A list (linked-list)

cryogen.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Wed, 12 Jun 2024 23:24:16 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>
1+
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 30 Jun 2024 11:16:36 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>

feed.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Wed, 12 Jun 2024 23:24:16 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>
1+
<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><atom:link href="https://clojure-doc.org/" rel="self" type="application/rss+xml"/><title>Clojure Guides</title><link>https://clojure-doc.org/</link><description>Clojure Documentation</description><lastBuildDate>Sun, 30 Jun 2024 11:16:36 -0700</lastBuildDate><generator>clj-rss</generator></channel></rss>

0 commit comments

Comments
 (0)