Skip to content

Commit

Permalink
errata
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed May 24, 2016
1 parent babc8a4 commit 9cab6f1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--- {}
4 changes: 2 additions & 2 deletions content/cftbat/core-functions-in-depth.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ <h3>map</h3>
<span class="tok-c1">; =&gt; ({:human 8.1, :critter 0.0}</span>
<span class="tok-p">{</span><span class="tok-ss">:human</span> <span class="tok-mf">7.3</span>, <span class="tok-ss">:critter</span> <span class="tok-mf">0.2</span><span class="tok-p">}</span>
<span class="tok-p">{</span><span class="tok-ss">:human</span> <span class="tok-mf">6.6</span>, <span class="tok-ss">:critter</span> <span class="tok-mf">0.3</span><span class="tok-p">}</span>
<span class="tok-p">{</span><span class="tok-ss">:human</span> <span class="tok-mf">5.0</span>, <span class="tok-ss">:critter</span> <span class="tok-mf">1.8</span><span class="tok-p">})</span>
<span class="tok-p">{</span><span class="tok-ss">:human</span> <span class="tok-mf">5.0</span>, <span class="tok-ss">:critter</span> <span class="tok-mf">1.1</span><span class="tok-p">})</span>
</code></pre></div></div>

<p class="Body">Good job laying off the human!</p>
Expand Down Expand Up @@ -260,7 +260,7 @@ <h3><a id="Anchor"></a>reduce</h3>
<span class="tok-ss">:min</span> <span class="tok-p">(</span><span class="tok-nb">inc </span><span class="tok-mi">10</span><span class="tok-p">))</span>
</code></pre></div></div>

<p class="Body">The function <code>assoc<code> takes three arguments: a map, a key, and a value. It returns derives a new map from the map you give it by <em>associating</em> the given key with the given value. For example, <code>(assoc {:a 1} :b 2))</code> would return <code>{:a 1 :b 2}</code></p>
<p class="Body">The function <code>assoc</code> takes three arguments: a map, a key, and a value. It derives a new map from the map you give it by <em>associating</em> the given key with the given value. For example, <code>(assoc {:a 1} :b 2)</code> would return <code>{:a 1 :b 2}</code></p>

<p class="Body"><span>Another use for </span><code>reduce</code><span> is to filter out keys from a map based on their value. In the following example, the anonymous function checks whether the value of a key-value pair is greather than 4. If it isn’t, then the key-value pair is filtered out. In the map </span><code>{:human 4.1 :critter 3.9}</code><span>, 3.9 is less than 4, so the </span><code>:critter</code><span> key and its 3.9 value are filtered out.</span></p>
<div class="listingblock"><div class="content"><pre class="pygments highlight"><code data-lang="clojure" class="block"><span class="tok-p">(</span><span class="tok-nb">reduce </span><span class="tok-p">(</span><span class="tok-k">fn </span><span class="tok-p">[</span><span class="tok-nv">new-map</span> <span class="tok-p">[</span><span class="tok-nb">key </span><span class="tok-nv">val</span><span class="tok-p">]]</span>
Expand Down
2 changes: 1 addition & 1 deletion content/cftbat/multimethods-records-protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h2>Records</h2>
<p class="Body"><span>We’ve created a new protocol, </span><code>WereCreature</code><span class="Default-Paragraph-Font"> </span><span>, with one method, </span><code>full-moon-behavior</code><span class="Default-Paragraph-Font"> </span>➋. At ➌, <code>defrecord</code> implements <code>WereCreature</code> for <code>WereWolf</code>. The most interesting part of the <code>full-moon-behavior</code> implementation is that you have access to <code>name</code>. You also have access to <code>title</code> and any other fields that might be defined for your record. You can also extend records using <code>extend-type</code> and <code>extend-protocol</code>.</p>
<p class="Body">When should you use records, and when should you use maps? In general, you should consider using records if you find yourself creating maps with the same fields over and over. This tells you that that set of data represents information in your application’s domain, and your code will communicate its purpose better if you provide a name based on the concept you’re trying to model. Not only that, but record access is more performant than map access, so your program will become a bit more efficient. Finally, if you want to use protocols, you’ll need to create a record.</p>
<h2>Further Study</h2>
<p class="BodyFirst">Clojure offers other tools for working with abstractions and data types. These tools, which I consider advanced, include <code>deftype</code>, <code>reify</code>, and <code>proxy</code>. If you’re interested in learning more, check out the documentation on data types at <em><a href="http://clojure.org/datatypes/">http://clojure.org/datatypes/</a></em>.</p>
<p class="BodyFirst">Clojure offers other tools for working with abstractions and data types. These tools, which I consider advanced, include <code>deftype</code>, <code>reify</code>, and <code>proxy</code>. If you’re interested in learning more, check out the documentation on data types at <em><a href="http://clojure.org/reference/datatypes/">http://clojure.org/datatypes/</a></em>.</p>
<h2>Summary</h2>
<p class="BodyFirst">One of Clojure’s design principles is to write to abstractions. In this chapter, you learned how to define your own abstractions using multimethods and prototypes. These constructs provide polymorphism, allowing the same operation to behave differently based on the arguments it’s given. You also learned how to create and use your own associative data types with <code>defrecord</code> and how to extend records to implement protocols.</p>
<p class="Body">When I first started learning Clojure, I was pretty shy about using multi­methods, protocols, and records. However, they are used often in Clojure libraries, so it’s good to know how they work. Once you get the hang of them, they’ll help you write cleaner code.</p>
Expand Down
10 changes: 5 additions & 5 deletions content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ <h2>Brave Clojure Quests</h2>
<h2>Learn by Email</h2>
<form action="//braveclojure.us1.list-manage.com/subscribe/post?u=60763b0c4890c24bd055f32e6&amp;id=9232ef71ee" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<p>
<em>The Clojure Atom</em> is a weekly email I'm
cooking up. Every Thursday, you'll get a single link
to a high-quality, free instructional resource. Once
it's ready, anyway. Sign up now so you don't miss a
single issue!
<em>The Clojure Atom</em> is a bi-weekly email I'm
cooking up. Every other Thursday, you'll get a single
link to a high-quality, free instructional
resource. Once it's ready, anyway. Sign up now so you
don't miss a single issue!
<div>
<input class="email" id="mce-EMAIL" name="EMAIL" placeholder="email address" required="" type="email" value="">
<input class="button" id="mc-embedded-subscribe"
Expand Down
1 change: 0 additions & 1 deletion lib/redcarpet_syntax_highlighter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ def block_code(code, language)
"<div class='code pygments'>" + Pygments.highlight(code, :lexer => language) + "</div>"
end
end

0 comments on commit 9cab6f1

Please sign in to comment.