AST

Structural annotations for Carp source forms.

ann walks a quoted source form and produces a dynamic map describing it — one variant per Carp special form, plus one per literal kind. unann reverses the process, reconstructing the source from a (possibly rewritten) annotation map. The pair lets you inspect, analyze, and rewrite Carp code as data without tripping over the irregular shapes of def/defn/let/match/register/etc.

ann

dynamic

Dynamic

                        (ann l)
                    

annotates a Carp source form with structural metadata.

Takes a quoted form l and returns a dynamic map. Every annotation has two common keys: 'value holds the original form, and 'type is a variant tag. Additional keys depend on the tag.

Literals:

  • 'symbol, 'string, 'boolean, 'character: just 'value.
  • 'number: 'value and 'width (one of 'int 'long 'float 'double 'byte).
  • 'unit: the empty list ().
  • 'array: 'value is an array of recursively annotated elements.

Special forms:

  • 'application: 'function, 'arguments.
  • 'def: 'name, 'bound-to, 'static? (false for defdynamic).
  • 'defn: 'name, 'arguments (raw), 'body, 'static? (false for defndynamic).
  • 'do: 'body (list), 'returns (last element).
  • 'while: 'condition, 'body.
  • 'if: 'condition, 'then, 'else.
  • 'quote, 'ref, 'deref: 'body.
  • 'deftype: 'name, 'body (raw members).
  • 'register: 'name, 'signature (raw), 'external-name (string or nil).
  • 'register-type: 'name, 'body (raw members or 'unknown), 'external-name (string or nil).
  • 'defmodule: 'name, 'body (list).
  • 'let: 'bindings (list of {'type 'let-binding 'name 'binding}), 'body.
  • 'fn: 'arguments (raw), 'body.
  • 'break: no extra fields.
  • 'set!: 'target, 'bound-to.
  • 'the: 'target-type (raw), 'body.
  • 'with: 'module (raw), 'body (list).
  • 'match / 'match-ref: 'scrutinee, 'cases (list of {'pattern 'body}; patterns are raw).

Unknown forms produce a macro-error.

unann

dynamic

Dynamic

                        (unann m)
                    

reconstructs a Carp source form from an annotation map produced by ann.

Walks the map by 'type tag and rebuilds the original form. The round- trip property holds: (unann (ann x)) equals x for every supported form. Because the reconstruction reads the variant-specific child keys rather than the original 'value slot, you can modify an annotation and unann will emit the rewritten form. Unknown type tags produce a macro-error.