You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: clojure+/print/objects_and_protocols.html
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -395,20 +395,20 @@ <h1 class="title">Printing Objects and Protocols in Clojure</h1>
395
395
<spanid="cb1-2"><ahref="#cb1-2" aria-hidden="true" tabindex="-1"></a> (<spanclass="va">#'clojure.core/print-object</span> x w))</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
<p>The syntax is <code>#object[CLASS-NAME HASH toString())]</code> and as you can see, the toString of an Object is <code>CLASS-NAME@HASH</code>. This can get pretty ugly:</p>
407
407
<divclass="sourceClojure">
408
408
<divclass="sourceCode" id="cb5"><preclass="sourceCode clojure code-with-copy"><codeclass="sourceCode clojure"><spanid="cb5-1"><ahref="#cb5-1" aria-hidden="true" tabindex="-1"></a>(async/chan)</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
<p>Hmmmm. not so nice. We’ll dig into this further below. But we also need to be aware that Clojure munges it’s names to make Java valid names. This matters for some things:</p>
444
444
<divclass="sourceClojure">
@@ -447,7 +447,7 @@ <h1 class="title">Printing Objects and Protocols in Clojure</h1>
447
447
<spanid="cb14-3"><ahref="#cb14-3" aria-hidden="true" tabindex="-1"></a> (.getName))</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
448
448
</div>
449
449
<divclass="printedClojure">
450
-
<divclass="sourceCode" id="cb15"><preclass="sourceCode clojure code-with-copy"><codeclass="sourceCode clojure"><spanid="cb15-1"><ahref="#cb15-1" aria-hidden="true" tabindex="-1"></a><spanclass="st">"clojure_PLUS_.print.objects_and_protocols$eval72670$_PERCENT__PERCENT___72671$_PERCENT__PERCENT__PERCENT___72672"</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
450
+
<divclass="sourceCode" id="cb15"><preclass="sourceCode clojure code-with-copy"><codeclass="sourceCode clojure"><spanid="cb15-1"><ahref="#cb15-1" aria-hidden="true" tabindex="-1"></a><spanclass="st">"clojure_PLUS_.print.objects_and_protocols$eval72686$_PERCENT__PERCENT___72687$_PERCENT__PERCENT__PERCENT___72688"</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
451
451
</div>
452
452
<p>Whoa, that’s pretty gross. We’d prefer to demunge the names at least.</p>
453
453
<divclass="sourceClojure">
@@ -460,7 +460,7 @@ <h1 class="title">Printing Objects and Protocols in Clojure</h1>
460
460
<spanid="cb17-2"><ahref="#cb17-2" aria-hidden="true" tabindex="-1"></a> (class-name))</span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
461
461
</div>
462
462
<divclass="printedClojure">
463
-
<divclass="sourceCode" id="cb18"><preclass="sourceCode clojure code-with-copy"><codeclass="sourceCode clojure"><spanid="cb18-1"><ahref="#cb18-1" aria-hidden="true" tabindex="-1"></a><spanclass="st">"clojure+.print.objects-and-protocols/eval72677/%%--72678/%%%--72679"</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
463
+
<divclass="sourceCode" id="cb18"><preclass="sourceCode clojure code-with-copy"><codeclass="sourceCode clojure"><spanid="cb18-1"><ahref="#cb18-1" aria-hidden="true" tabindex="-1"></a><spanclass="st">"clojure+.print.objects-and-protocols/eval72693/%%--72694/%%%--72695"</span></span></code><buttontitle="Copy to Clipboard" class="code-copy-button"><iclass="bi"></i></button></pre></div>
464
464
</div>
465
465
<p>Notice the <code>/evalNNNNN/</code> part? To create a function, Clojure creates a new class. The <code>/evalNNNNN/</code> counts every time it evaluates. This is useful in the sense that it identifies the class for that evaluation. But we almost never care for that detail (more on that later). For the same reason our strangely named functions have <code>--NNNNN</code> appended to them, because they are sub evaluations of the top-level evaluation.</p>
466
466
<p>Let’s do away with that noise for the moment:</p>
@@ -761,7 +761,7 @@ <h1 class="title">Printing Objects and Protocols in Clojure</h1>
0 commit comments