dbg) designPuzzle solvers want to see intermediate values while working out a solution, without rewriting code to do it and without the debug output affecting timings on a normal run. Elf owns the macro so it controls the formatting (pretty printing, labels, size limits) and can make the calls disappear entirely when debugging is off.
(dbg form) prints a labelled value and returns the value unchanged, so it
can wrap any expression, including a step in -> or ->> pipelinesbb aoc solve --debug and bb aoc test --debug print debug output. Without
--debug, dbg calls have no run-time cost: they are removed when the
solution file is loaded--no-pretty prints each value
on one linedbg takes exactly one
argument so it works in both -> and ->>solve| Approach | Trade-off | |
|---|---|---|
| A (chosen) | Decide at load time: the macro reads a setting when it expands; when off it expands to the bare form | Zero cost when off. The setting must be chosen before the solution is loaded, so toggling needs a reload (fine for the CLI, which loads fresh each run) |
| B | Runtime check per call | Live toggling, but a check on every call. Babashka interprets code, so that check costs something in hot loops, which conflicts with the zero-cost goal |
| C | tap> | Standard, but a per-call cost, and the formatting is left to whatever is listening, while the goal is for elf to own it |
Chosen with the user: A.
aoc-clj-elf.debugsettings: an atom {:enabled? true :pretty? true :print-length 100 :print-level 10}
:enabled? defaults to true, so dbg works in a REPL, where the runner isn't
involved ("if you typed dbg, you want to see it")(dbg form) macro:
:enabled? is false at expansion time it expands to formform once, prints a label and
the value, and returns the value[<file>:<line>] <form> =>, dimmed with bling.
<file> is the path relative to the working directory (e.g. src/y2026/d4.clj)<line> comes from &form metadata, falling back to form's metadata (threading
macros drop &form's metadata); the :<line> part is left out if neither has one<form> is the form as written after threading expansion*print-length*/*print-level* bound from settings, using
clojure.pprint/pprint when :pretty? is on, else prn*out*, the same stream solution output already usessolve and test accept --debug (boolean, default false) and
--pretty/--no-pretty (boolean, default true):enabled? (from --debug) and :pretty? in settingsnew, get) ignore these options and don't list them in helpresources/solution.template adds [aoc-clj-elf.debug :refer [dbg]] to the ns
requires.
--debug and --no-pretty, the
REPL default, and a note that debug output is included in timings when onIn babashka: load-time elision works (expanded to the bare form, no output);
&form has no line inside ->> but the wrapped form does; *print-length*
is respected by pprint.
solve and
test onlyCan you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |