trivial-inspect

2026-11-29

Portable toolkit for interactive inspectors.

Upstream URL

Author

Artyom Bologov

License

BSD-2 Clause
README
<title>Trivial Inspect</title> <main> <h1>Trivial Inspect</h1> <p> <strong>A portable toolkit for building inspectors</strong> <p> Trivial Inspect exposes a set of utils useful in building inspectors akin to standard <code>inspect</code> and <code>describe</code>. The goal is to provide as much information as possible. Including the implementation-specific info. <h2 id=getting-started>Getting Started</h2> <h3 id=user-setup>Library user setup</h3> <p> If you want to use the library without hacking on it, clone the Git repository to where ASDF can find it: <pre lang=sh> git clone https://codeberg.org/aartaka/trivial-inspect ~/.local/share/common-lisp/source/ </pre> <p> And then load <code>"trivial-inspect"</code> in the REPL: <pre lang=lisp> (asdf:load-system "trivial-inspect") ;; or, if you use Quicklisp (ql:quickload "trivial-inspect") </pre> <h3 id=contributor-setup>Contributor/developer setup</h3> <p> In case you want to hack on <code>(#| TMPL_VAR name |#)</code>, all the dependencies are bundled as submodules, you need to do a recursive clone <pre lang=sh> git clone --recursive https://codeberg.org/aartaka/(#| TMPL_VAR name |#) </pre> <p> In case you initially cloned the repository without submodules, do <pre lang=sh> git submodule update --init -- deps/ </pre> <p> After that, you can run <ul> <li> an Emacs-friendly development server: <code>make slynk</code> or <code>make swank</code> <li> REPL with all the dependencies and Trivial Inspect preloaded: <code>make repl</code> <!-- <li> tests: <code>(asdf:test-system "trivial-inspect")</code> or run <code>make check</code> from CLI.--> </ul> <p> You can also use the bundled <a href=guix.scm>guix.scm</a> to install it on Guix. <h2 id=api>APIs</h2> <p> Two main entry points of this library are <code>fields</code> and <code>description</code>: <h3 id=fields>fields (object) -&gt; fields</h3> <p> <code>fields</code> returns a list of inspect properties for a given object Each property is a list of <ul> <li>Index <li> Property name (either index, keyword, or some standard library symbol, usually a getter function) <li> Value of the property <li> And optional setter to override this property. A function of two arguments—new value and old value. </ul> <pre lang=lisp> (trivial-inspect:fields #'identity) ;; ((0 :self #<function identity>) (1 :id 1407351035) ;; (2 class-of #<sb-pcl:system-class common-lisp:function> #<function # {100A28547B}>) ;; (3 type-of compiled-function) (4 :name identity) (5 :arguments (sb-impl::thing)) ;; (6 compiled-function-p t) (7 :ftype (function # #)) ;; (8 :expression nil) ;; (9 lambda-list-keywords (&allow-other-keys &aux &body &environment &key sb-int:&more &optional &rest &whole)) ;; (10 call-arguments-limit 1073741824) (11 lambda-parameters-limit 1073741824)) (trivial-inspect:fields nil) ;; ((0 :self nil) (1 :id 1342177559) ;; (2 class-of #<built-in-class common-lisp:null> nil) ;; (3 type-of null) (4 length 0) ;; (5 symbol-name "NIL") (6 symbol-package #<package "COMMON-LISP">) ;; (7 :visibility :external #<function # {100CFF5F0B}>) ;; (8 symbol-value nil #<function # {100CFF5F2B}>) (9 symbol-plist nil)) (trivial-inspect:fields (find-class 'standard-object)) ;; ((0 :self #<standard-class common-lisp:standard-object>) (1 :id 68721940739) ;; (2 class-of #<standard-class common-lisp:standard-class> ;; #<function (lambda (trivial-inspect::new-value trivial-inspect::_) :in trivial-inspect:fields) {1003A7BAEB}>) ;; (3 :slot-definitions ;; (#<sb-mop:standard-effective-slot-definition sb-pcl::%type> #<sb-mop:standard-effective-slot-definition sb-pcl::source> ..))) </pre> <h3 id=description>description (object &optional stream)</h3> <p> <code>description</code> returns/prints a human-readable description of the given object. Quite opinionated, but optimized for maximum useful info (if you have an idea for a better format, I'm open to discussion!) Usually includes type and printable representation, possibly followed by prettified <code>fields</code> and other info. <pre lang=lisp> (trivial-inspect:description #'+ t) ;; Compiled-function + (&REST NUMBERS) ;; : (&REST NUMBER) -> (VALUES NUMBER &OPTIONAL) ;; Return the sum of its arguments. With no args, returns 0. (trivial-inspect:description 'standard-class t) ;; Symbol STANDARD-CLASS (EXTERNAL to COMMON-LISP) [class] (trivial-inspect:description (find-class 'standard-class) t) ;; Standard-class #<STANDARD-CLASS COMMON-LISP:STANDARD-CLASS> </pre> <h2 id=customization>Customization Points</h2> <p> <code>function-lambda-expression</code> returns wildly different results across implementations and often misses the metadata for even simple functions. Thus the need for <a https://github.com/aartaka/graven-image/blob/master/source/function-lambda-expression.lisp>re-implementation and improvement</a>. <code>*function-lambda-expression-fn*</code> allows providing your own <code>function-lambda-expression</code> implementation in case you find the implementation-specific one lacking in some way. <p> <code>*documentation-fn*</code> serves the same purpose, but for <code>documentation</code>. It's less likely to be useful, but is included anyway. Who knows, maybe you come up with a better documentation function incorporating function arglists, class slots etc. Do come up with it, everyone in the community will benefit from that! <style> /* Light theme. */ :root { --bg: var(--light, papayawhip); --fg: var(--dark, black); --accent: var(--light-accent, maroon); --on-accent: var(--bg); --gray: var(--neutral, darkgray); } * { font-palette: ligth; } /* Dark theme. */ @media (prefers-color-scheme: dark) { :root { --bg: var(--dark, black); --fg: var(--light, papayawhip); --accent: var(--dark-accent, lightcoral); --on-accent: var(--bg, black); --gray: var(--neutral, lightgray); } * { font-palette: dark; } } /* Increased accessibility mode. */ @media (forced-colors: active) { --bg: Canvas; --fg: CanvasText; --accent: AccentColor; --on-accent: AccentColorText; } * { box-sizing: border-box; border-spacing: 0; scrollbar-color: var(--accent) rgba(0, 0, 0, 0); caret-color: var(--accent); accent-color: var(--accent); } ::selection, mark, ::target-text { background-color: var(--accent); color: var(--on-accent); border-radius: 0.2em; padding: 0 0.1em; } ::marker { color: var(--accent); } body { margin: 0; padding: 1em; background: var(--bg); color: var(--fg); min-height: 100%; font-size: max(1em, 16px, 1rem); } main { padding: 1em; } @media (min-device-width: 500px) { main { margin: 0 auto; max-width: 70em; } } a { color: inherit; font-family: inherit; font-style: italic; } a:hover { background-color: var(--accent); color: var(--on-accent); } dt { color: var(--accent); font-weight: bold; } .note { border-radius: 0.2em; border: 0.1em solid var(--accent); padding: 0 1em; margin: 1em 0; } pre { overflow-x: auto; } h1[id]::after, h2[id]::after, h3[id]::after, h4[id]::after, h5[id]::after, h6[id]::after { content: " (#" attr(id) ")"; color: var(--gray); } </style>

Dependencies (3)

  • slime
  • sly
  • trivial-arguments

Dependents (0)

    • GitHub
    • Quicklisp