Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typo #119

Merged
merged 1 commit into from Feb 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/cftbat/multimethods-records-protocols.html
Expand Up @@ -108,7 +108,7 @@ <h3>Protocols</h3>
<div class="listingblock"><div class="content"><pre class="pygments highlight"><code data-lang="clojure" class="block"><span class="tok-p">(</span><span class="tok-nf">feelings-about</span> <span class="tok-p">[</span><span class="tok-nv">x</span><span class="tok-p">]</span> <span class="tok-p">[</span><span class="tok-nv">x</span> <span class="tok-o">&amp;</span> <span class="tok-nv">others</span><span class="tok-p">])</span>
</code></pre></div></div>

<p class="Body">By defining a protocol, you’re defining an abstraction, but you haven’t yet defined how that abstraction is implemented. It’s like you’re reserving <span>names for behavior (in this example, you’re reserving </span><code>thoughts</code><span> and </span><code>feelings</code><span>), </span>but you haven’t defined what exactly the behavior should be. If you were <span>to evaluate </span><code>(thoughts "blorb")</code><span>, you would get an exception that reads, “No implementation of method: thoughts of protocol: data-psychology/Psychodynamics found for class: java.lang.String.” Protocols dispatch on the</span> first argument’s type, so when you call <code>(thoughts "blorb")</code>, Clojure tries to look up the implementation of the <code>thoughts</code> method for strings, and fails.</p>
<p class="Body">By defining a protocol, you’re defining an abstraction, but you haven’t yet defined how that abstraction is implemented. It’s like you’re reserving <span>names for behavior (in this example, you’re reserving </span><code>thoughts</code><span> and </span><code>feelings-about</code><span>), </span>but you haven’t defined what exactly the behavior should be. If you were <span>to evaluate </span><code>(thoughts "blorb")</code><span>, you would get an exception that reads, “No implementation of method: thoughts of protocol: data-psychology/Psychodynamics found for class: java.lang.String.” Protocols dispatch on the</span> first argument’s type, so when you call <code>(thoughts "blorb")</code>, Clojure tries to look up the implementation of the <code>thoughts</code> method for strings, and fails.</p>
<p class="Body">You can fix this sorry state of affairs by <em>extending</em> the string data type to <em>implement</em> the <code>Psychodynamics</code> protocol:</p>
<div class="listingblock"><div class="content"><pre class="pygments highlight"><code data-lang="clojure" class="block"><span class="tok-err">➊</span> <span class="tok-p">(</span><span class="tok-nf">extend-type</span> <span class="tok-nv">java.lang.String</span>
<span class="tok-err">➋</span> <span class="tok-nv">Psychodynamics</span>
Expand Down