|
114 | 114 |
|
115 | 115 | <meta property="og:title" content="Clean object printing by removing extraneous – Clojure Civitas"> |
116 | 116 | <meta property="og:description" content=""> |
117 | | -<meta property="og:image" content="https://clojurecivitas.github.io/clojure/print_object/images/civitas-icon.svg"> |
| 117 | +<meta property="og:image" content="https://clojurecivitas.github.io/clojure/print_object/objection.jpg"> |
118 | 118 | <meta property="og:site_name" content="Clojure Civitas"> |
119 | 119 | </head> |
120 | 120 |
|
@@ -406,34 +406,40 @@ <h1 class="title">Clean object printing by removing extraneous</h1> |
406 | 406 | <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> (<span class="va">#'clojure.core/print-object</span> x w))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
407 | 407 | </div> |
408 | 408 | <div class="printedClojure"> |
409 | | -<div class="sourceCode" id="cb2"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.lang.MultiFn <span class="bn">0x3eb022c2</span> <span class="st">"clojure.lang.MultiFn@3eb022c2"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 409 | +<div class="sourceCode" id="cb2"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.lang.MultiFn <span class="bn">0xec824ca</span> <span class="st">"clojure.lang.MultiFn@ec824ca"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
410 | 410 | </div> |
411 | 411 | <div class="sourceClojure"> |
412 | 412 | <div class="sourceCode" id="cb3"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a>(Object.)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
413 | 413 | </div> |
414 | 414 | <div class="printedClojure"> |
415 | | -<div class="sourceCode" id="cb4"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>#object[java.lang.Object <span class="bn">0x232f05b0</span> <span class="st">"java.lang.Object@232f05b0"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 415 | +<div class="sourceCode" id="cb4"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>#object[java.lang.Object <span class="bn">0x56ec31ca</span> <span class="st">"java.lang.Object@56ec31ca"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
416 | 416 | </div> |
417 | 417 | <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>. For most objects this becomes quite a long string.</p> |
418 | 418 | <div class="sourceClojure"> |
419 | 419 | <div class="sourceCode" id="cb5"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>(async/chan)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
420 | 420 | </div> |
421 | 421 | <div class="printedClojure"> |
422 | | -<div class="sourceCode" id="cb6"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.core.async.impl.channels.ManyToManyChannel <span class="bn">0x40a0c58c</span> <span class="st">"clojure.core.async.impl.channels.ManyToManyChannel@40a0c58c"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 422 | +<div class="sourceCode" id="cb6"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.core.async.impl.channels.ManyToManyChannel <span class="bn">0x1ece307c</span> <span class="st">"clojure.core.async.impl.channels.ManyToManyChannel@1ece307c"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 423 | +</div> |
| 424 | +<div class="quarto-figure quarto-figure-center"> |
| 425 | +<figure class="figure"> |
| 426 | +<p><img src="objection.jpg" class="img-fluid figure-img"></p> |
| 427 | +<figcaption>Objection!</figcaption> |
| 428 | +</figure> |
423 | 429 | </div> |
424 | 430 | <p>Functions are printed as objects</p> |
425 | 431 | <div class="sourceClojure"> |
426 | 432 | <div class="sourceCode" id="cb7"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>(<span class="kw">fn</span> [x] x)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
427 | 433 | </div> |
428 | 434 | <div class="printedClojure"> |
429 | | -<div class="sourceCode" id="cb8"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.print_object.remove_extraneous$eval22346$fn__22347 <span class="bn">0x43f3ff50</span> <span class="st">"clojure.print_object.remove_extraneous$eval22346$fn__22347@43f3ff50"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 435 | +<div class="sourceCode" id="cb8"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.print_object.remove_extraneous$eval22346$fn__22347 <span class="bn">0x17a3aa29</span> <span class="st">"clojure.print_object.remove_extraneous$eval22346$fn__22347@17a3aa29"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
430 | 436 | </div> |
431 | 437 | <p>It’s quite easy to miss the fact that it is a function as we are looking for a tiny little <code>fn</code> in a sea of text. If, like me, you are fond of the <a href="../../code_interview/beating/with_stupid_stuff/z_combinator_gambit.html">odd lambda calculus excursion</a>, things get even more hectic.</p> |
432 | 438 | <div class="sourceClojure"> |
433 | 439 | <div class="sourceCode" id="cb9"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>((<span class="kw">fn</span> [x] (<span class="kw">fn</span> [v] ((x x) v))) (<span class="kw">fn</span> [y] y))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
434 | 440 | </div> |
435 | 441 | <div class="printedClojure"> |
436 | | -<div class="sourceCode" id="cb10"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.print_object.remove_extraneous$eval22350$fn__22351$fn__22352 <span class="bn">0x677f0c10</span> <span class="st">"clojure.print_object.remove_extraneous$eval22350$fn__22351$fn__22352@677f0c10"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
| 442 | +<div class="sourceCode" id="cb10"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>#object[clojure.print_object.remove_extraneous$eval22350$fn__22351$fn__22352 <span class="bn">0x11ad162d</span> <span class="st">"clojure.print_object.remove_extraneous$eval22350$fn__22351$fn__22352@11ad162d"</span>]</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
437 | 443 | </div> |
438 | 444 | <p>Yikes! what an eyesore. This is not an academic issue specific to lambda calculus. Any function created from inside a function is helpfully identifiable through the <code>fn$fn</code> nesting. We create these quite regularly, and they are often printed in stack traces. I’m sure you have seen them when you map an inline function across a seq, and there is a bug in the anonymous function.</p> |
439 | 445 | <div class="sourceClojure"> |
@@ -495,7 +501,7 @@ <h1 class="title">Clean object printing by removing extraneous</h1> |
495 | 501 | <div class="printedClojure"> |
496 | 502 | <div class="sourceCode" id="cb22"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="st">"fn$fn"</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> |
497 | 503 | </div> |
498 | | -<p>So short, so sweet.</p> |
| 504 | +<p>So short, so sweet. If it’s a function, why call it an object?</p> |
499 | 505 | <div class="sourceClojure"> |
500 | 506 | <div class="sourceCode" id="cb23"><pre class="sourceCode clojure code-with-copy"><code class="sourceCode clojure"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>(<span class="bu">defn</span><span class="fu"> object-str </span>^String [x]</span> |
501 | 507 | <span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a> (<span class="kw">str</span> (<span class="kw">if</span> (<span class="kw">fn?</span> x) <span class="st">"#fn"</span> <span class="st">"#object"</span>)</span> |
|
0 commit comments