Clojure core environment and runtime library providing a dynamic, general-purpose programming language on the JVM.
—
Development and debugging utilities through specialized namespaces: clojure.stacktrace for Clojure-oriented stack trace printing, clojure.inspector for graphical data structure inspection, and clojure.template for code templating and generation.
Tools for printing and analyzing stack traces with Clojure-specific formatting and information extraction.
(clojure.stacktrace/root-cause throwable)
;; Returns the last 'cause' Throwable in a chain of Throwables
;; throwable: Throwable to analyze
;; Returns: root cause Throwable
(clojure.stacktrace/print-trace-element stack-trace-element)
;; Prints a Clojure-oriented view of one stack trace element
;; stack-trace-element: StackTraceElement to print
;; Returns: nil (prints to *out*)
(clojure.stacktrace/print-throwable throwable)
;; Prints the class and message of a Throwable, includes ex-data if present
;; throwable: Throwable to print
;; Returns: nil (prints to *out*)
(clojure.stacktrace/print-stack-trace throwable)
;; Prints stack trace for throwable with Clojure-specific formatting
;; throwable: Throwable to print trace for
;; Returns: nil (prints to *out*)
(clojure.stacktrace/print-cause-trace throwable)
;; Prints stack trace including all causes in the exception chain
;; throwable: Throwable to print full cause chain for
;; Returns: nil (prints to *out*)
(clojure.stacktrace/e)
;; Prints stack trace of most recent exception (*e)
;; Returns: nil (prints to *out*)Graphical inspection tools for exploring Clojure data structures using Swing components.
(clojure.inspector/inspect data)
;; Opens graphical inspector window for data structure
;; data: Clojure data structure to inspect
;; Returns: inspector component
(clojure.inspector/inspect-tree data)
;; Opens tree view inspector for hierarchical data
;; data: nested data structure
;; Returns: JFrame with tree view
(clojure.inspector/inspect-table data)
;; Opens table view inspector for tabular data
;; data: sequence of maps or map-entry collections
;; Returns: JFrame with table view(clojure.inspector/atom? x)
;; Returns true if x is an atomic value (not a collection)
;; x: value to test
;; Returns: boolean
(clojure.inspector/collection-tag x)
;; Returns tag indicating collection type for inspector display
;; x: value to categorize
;; Returns: keyword (:entry, :seqable, :seq, or :atom)
(clojure.inspector/tree-model data)
;; Creates TreeModel for Swing JTree component
;; data: nested data structure
;; Returns: javax.swing.tree.TreeModel
(clojure.inspector/list-model provider)
;; Creates list model for inspector interface
;; provider: data provider function
;; Returns: list model for Swing componentsMacros for generating repetitive code patterns using template expansion.
(clojure.template/apply-template argv expr values)
;; For use in macros - recursively replaces argument symbols in expr with values
;; argv: argument vector (symbols)
;; expr: quoted expression using symbols from argv
;; values: sequence of replacement values
;; Returns: modified expr with substitutions
;; Macro for repeated template expansion
(clojure.template/do-template argv expr & values)
;; Repeatedly copies expr for each group of arguments in values
;; argv: argument vector as in defn
;; expr: template expression
;; values: arguments automatically partitioned by argv length
;; Returns: do block with expanded expressionsUsage Examples:
;; Stack trace analysis examples
(require '[clojure.stacktrace :as st])
;; Analyze exception chain
(try
(throw (Exception. "Inner" (RuntimeException. "Root cause")))
(catch Exception e
(st/root-cause e)))
;; => #<RuntimeException java.lang.RuntimeException: Root cause>
;; Print detailed stack trace
(try
(/ 1 0)
(catch Exception e
(st/print-cause-trace e)))
;; Prints full cause chain with Clojure-formatted stack trace
;; Print most recent exception
(/ 1 0) ; causes exception
(st/e) ; prints stack trace of *e
;; Custom exception with data
(try
(throw (ex-info "Custom error" {:code 404 :resource "/api/users"}))
(catch Exception e
(st/print-throwable e)))
;; Prints: clojure.lang.ExceptionInfo: Custom error
;; {:code 404, :resource "/api/users"}
;; Data structure inspector examples
(require '[clojure.inspector :as inspect])
;; Inspect nested data structure
(def sample-data
{:users [{:id 1 :name "Alice" :roles [:admin :user]}
{:id 2 :name "Bob" :roles [:user]}]
:config {:database {:host "localhost" :port 5432}
:logging {:level :info :file "app.log"}}})
;; Open graphical inspector (requires GUI environment)
(inspect/inspect sample-data)
;; Inspect as tree view
(inspect/inspect-tree sample-data)
;; Inspect tabular data as table
(inspect/inspect-table (:users sample-data))
;; Check data characteristics
(inspect/atom? 42) ; => true
(inspect/atom? [1 2 3]) ; => false
(inspect/collection-tag {:a 1}) ; => :seqable
;; Code template examples
(require '[clojure.template :as tmpl])
;; Apply template function (for macro writing)
(tmpl/apply-template '[x y] '(+ x y (* x y)) '[3 4])
;; => (+ 3 4 (* 3 4))
;; Template macro usage
(macroexpand
'(tmpl/do-template [op a b]
(defn ~(symbol (str "test-" op)) [] (~op ~a ~b))
+ 2 3
- 5 2
* 4 6))
;; Expands to:
;; (do
;; (defn test-+ [] (+ 2 3))
;; (defn test-- [] (- 5 2))
;; (defn test-* [] (* 4 6)))
;; Real-world template example - generating multiple similar functions
(tmpl/do-template [name pred type-name]
(defn ~name [x]
(if (~pred x)
x
(throw (IllegalArgumentException.
(str "Expected " ~type-name ", got " (type x))))))
ensure-string string? "string"
ensure-number number? "number"
ensure-vector vector? "vector"
ensure-map map? "map")
;; Results in:
;; (defn ensure-string [x] ...)
;; (defn ensure-number [x] ...)
;; (defn ensure-vector [x] ...)
;; (defn ensure-map [x] ...)
;; Template for test generation
(tmpl/do-template [input expected]
(is (= ~expected (my-function ~input)))
"hello" "HELLO"
"world" "WORLD"
"" ""
nil nil)
;; Template for property access
(tmpl/do-template [prop-name getter setter field]
(do
(defn ~getter [obj] (~field obj))
(defn ~setter [obj val] (assoc obj ~field val)))
name get-name set-name :name
age get-age set-age :age
email get-email set-email :email)
;; Working with inspector programmatically
(defn debug-inspect [label data]
(println (str "Inspecting: " label))
(inspect/inspect data)
data) ; return data for chaining
;; Use in threading macro
(-> {:a 1 :b 2}
(assoc :c 3)
(debug-inspect "after adding :c")
(dissoc :a)
(debug-inspect "after removing :a"))Install with Tessl CLI
npx tessl i tessl/maven-org-clojure--clojure