2022-10-03

Published: Nov 01, 2022Last modified: Apr 05, 2023
Word count: 442Backlinks: 2

use aero for all clawe config?

vs rewrite-clj? maybe aero uses it already?

The current problem is preserving space and comments for files that are update both by hand and by machine.

clerk 'bug' figured out! It was my own config, of course.

I've been seeing quite a bit of:

The map literal starting with [0 2 1 2 1 1 0 1 0] contains 101 form(s). Map literals must contain an even number of forms.

The 101 here was showing up often, and is a strong clue at the actual issue, for any of you sherlock holmes debuggers.

I dug in and learned some more clerk internals, reading more of the sci_viewer,

the devloop, and adding logs. I was struggling to get full maps to print (or so

i thought). I wanted to get at the actual string to reproduce the

edamame/parse-string error in isolation, but I was confused as to why I

couldn't get full maps to print. I was seeing alot of:

#_(in some larger map structure)
[0 2 1 2 1 1 1 1] false ...}}

I mistakenly assumed the ... was some pretty-print or js console truncation... eventually I realized it was the *print-length*, and was being added by a pr-str in clerk somewhere.

I set *print-length* to 50 in my cider config when initing any cider repl:

(setq cider-repl-init-code (append cider-repl-init-code '("(set! *print-length* 50)")))

This is to prevent lag when evaling things against the repl - huge values can sometimes cause an annoyingly long pause when trying to display results inline. This fixes some of those cases.

The immediate fix was to update my clerk-show and other clerk bindings to unset *print-length*:

(defun russ/clerk-show ()
  (interactive)
  (save-buffer)
  (let
      ((filename (buffer-file-name)))
    (when filename
      (cider-interactive-eval
       (concat "
(with-bindings {#'*print-length* false}
  (nextjournal.clerk/show! \"" filename "\"))")))))

(defun russ/clawe-notebooks-update ()
  (interactive)
  (save-buffer)
  (let
      ((filename (buffer-file-name)))
    (when filename
      (cider-interactive-eval
       (concat "
(with-bindings {#'*print-length* nil}
  (notebooks.clerk/update-open-notebooks))")))))

Longer term, clerk should probably make sure to unset print-length in all cases, as it eventually leads to a crash on the frontend if anything is truncated that way.

I opened a small PR addressing it in clerk here: https://github.com/nextjournal/clerk/pull/224

You can evaluate partial threads in cider, calva, etc

Did you know that cider and other clojure repl tools support evaluating threads (thread-first, thread-last) up to the cursor (called the 'point' in emacs).

Very often when debugging threads, I comment out the last few functions in a thread, to see what the first half of it is producing.

In a thread in the clojurians #gratitude channel, pez pointed out that evaluating a partial thread is supported.

WUT. Today I Learned!

As an example, in a thread-last usage like:

(->>
      (items-with-tags #{"til"})
      (mapcat org-crud.markdown/item->md-body)
      (string/join "\n"))

You can evaluate the result of the first two calls by invoking

cider-eval-sexp-up-to-point with the point (>|<) somewhere after the second form:

(->>
      (items-with-tags #{"til"})
      (mapcat org-crud.markdown/item->md-body)
 >|<  (string/join "\n"))

Then, you can inspect that value as usual with cider-inspect.

it wasn't laziness

(if (seq []) :hi :bye)
(if [] :hi :bye)

Backlinks