Fork me on GitHub
#nextjournal
<
2021-12-16
>
respatialized21:12:51

can I set the paging limit for seqs in clerk manually? I've got a rather large lazy sequence in a notebook that clerk seems to be a little too eager to print.

mkvlr21:12:57

not yet. Is it a very deeply nested structure?

mkvlr21:12:15

or I guess the answer is, it depends

respatialized21:12:45

cartesian product. not nested, just very long.

mkvlr21:12:13

hmm, that shouldn’t be a problem

mkvlr21:12:22

can you maybe make a small repro?

mkvlr21:12:35

and it’s the latest version of Clerk? 0.4.305?

respatialized22:12:36

correct - v`0.4.305`. this approximation isn't quite as slow as the actual dataset I'm encountering problems with, but it does demonstrate that rebinding *bounded-count-limit* doesn't appear to limit the number of results it says are there (I'm still seeing "10M+ more..."). My expectation is that rebinding that var gives the printer a lower estimate of how much of the value to consume, but would the binding affect what happens on the "client side" (e.g. SCI/the browser context)?

(require '[clojure.math.combinatorics :as combo])

(binding [nextjournal.clerk.config/*bounded-count-limit* 500]
(def long-sequence
 (->> (range 2 18)
      (map #(range 1 %))
      (apply combo/cartesian-product)
      (map #(map (fn [v] (if (odd? v) (inc v) v)) %))
)))

mkvlr22:12:59

this value will only affect caching, but not what gets send the to browser. The browser will only receive a tiny preview (first 20 elements)

mkvlr22:12:10

Ill try this example tomorrow, will report back

mkvlr15:12:00

this works fine for me. Do you run into any issues?

mkvlr15:12:00

if you want to affect the counting, binding doesn’t work because after we eval the binding is reset to it’s root value, but alter-var-root works:

mkvlr15:12:36

or you can set the JVM prop: (System/getProperty "clerk.bounded-count-limit")

mkvlr15:12:55

but in your case the bounded-count with 1_000_000 seems fine? Clerk isn’t trying to print the whole thing, only does a bounded count…

respatialized16:12:55

my real case has a more expensive map fn than the repro, so a 1M bounded count is pretty slow for me (perhaps that means I should be trying to speed up my function instead of trying to curtail the clerk printer 😉). thanks for following up.

mkvlr17:12:02

ok, hope the alter var root thing works for you then

jackrusher19:12:04

maybe also consider just using (take) to bound how much of the seq gets realized 🙂 one of the nice things about Clerk is that you have all your usual Clojure techniques with you, so they just transfer to these situations

respatialized20:12:14

the issue is that it tries to print a def'd var that points to the sequence, forcing (some) realization at the point of definition when I would prefer to defer evaluation