sigildocs

(sigil inspect)

(sigil inspect) - Value introspection for machine consumers.

Provides type-tagged dict representations of any Sigil value, suitable for serialization to JSON (via MCP) or S-expressions (via nREPL).

(import (sigil inspect))

(inspect 42)          ; => #{ type: 'integer value: 42 }
(inspect '(1 2 3))   ; => #{ type: 'list length: 3 elements: #(...) }

Exports

inspectprocedure

Serialize any value to a type-tagged dict for machine consumers.

Returns a dict with at least a type: key. Compound types are recursively inspected up to DEPTH levels. Collections with more than MAX-ELEMENTS items are truncated with truncated: #t.

Examples:

(inspect 42)             ; => #{ type: 'integer value: 42 }
(inspect "hi")           ; => #{ type: 'string value: "hi" length: 2 }
(inspect '(1 2) 1)      ; truncates nested compounds at depth 1

Serialize an exception to a type-tagged dict.

For proper exceptions (created via error, raise, etc.), includes kind, message, irritants, and stack trace. For non-exception values that were raised, wraps them as a generic error.

Examples:

(guard (e (#t (inspect-exception e)))
  (error "oops" 'detail))
;; => #{ type: 'error message: "oops" irritants: #(...) ... }