On this page:
debug-enabled?
current-debug-printer
debug
debug*
define-debug
define-values-debug
let-debug
let*-debug
letrec-debug
let-values-debug
let*-values-debug
letrec-values-debug
with-pretty-indent
exn-context
debug-in
debug-out
Version: 4.1.3.8

4 Debugging tools

 (require (planet untyped/unlib/debug))

Utilities for printing the runtime values of variables for debugging purposes, with minimal disruption to code structure.

(debug-enabled?)  boolean?
(debug-enabled? val)  void?
  val : boolean?

Boolean parameter for enabling or disabling the printing of debugging information. Defaults to #t.

(current-debug-printer)  (-> string? any void?)
(current-debug-printer proc)  void?
  proc : (-> string? any void?)

Parameter controlling the formatting of printed debugging information. Value must be a procedure that takes a message and a value and returns void. The default value prints the message and a colon on one line and pretty-prints the value (slightly indented) on subsequent lines.

(debug val)  any
  val : any

Prints val and returns it transparently.

Examples:

  > (length (debug "square"
                   (for/list ([j '(1 2 3 4 5)])
                     (for/list ([i '(1 2 3 4 5)])
                       i))))

  square:

    ((1 2 3 4 5)

     (1 2 3 4 5)

     (1 2 3 4 5)

     (1 2 3 4 5)

     (1 2 3 4 5))

  5

(debug* proc arg ...)  any
  proc : procedure?
  arg : any

Applies proc to args and prints and returns the return value transparently.

Examples:

  > (add1 (debug* "message" * 2 2))

  message:

    4

  5

(define-debug id expr)

Expands to a define form that prints the value of id as a side effect.

Examples:

  > (define-debug test-data
      (+ 1 2 3))

  test-data:

    6

(define-values-debug (id ...) expr)

Like define-debug but expands to a define-values form.

Examples:

  > (define-values-debug (a b)
      (values (+ 1 2) (+ 3 4)))

  (a b):

    (3 7)

(let-debug ([id expr] ...) expr ...)

Expands to a let form that prints the value of each id as it is assigned.

Examples:

  > (let-debug ([a 1] [b 2])
      (+ a b))

  a:

    1

  b:

    2

  3

(let*-debug ([id expr] ...) expr ...)

Like let-debug but expands to a let* form.

(letrec-debug ([id expr] ...) expr ...)

Like let-debug but expands to a letrec form.

(let-values-debug ([(id ...) expr] ...) expr ...)

Expands to a let-values form that prints the value of each id as it is assigned.

Examples:

  > (let-values-debug ([(a b) (values 1 2)] [(c d) (values 3 4)])
      (+ a b c d))

  (a b):

    (1 2)

  (c d):

    (3 4)

  10

(let*-values-debug ([(id ...) expr] ...) expr ...)

Like let-values-debug but expands to a let*-values form.

(letrec-values-debug ([(id ...) expr] ...) expr ...)

Like letrec-values-debug but expands to a letrec-values form.

(with-pretty-indent prefix expr ...)

Parameterizes the pretty-print-print-line parameter to a procedure that acts the same as the default, except that every line is prefixed with prefix. prefix must be a string.

Examples:

  > (define square
      (for/list ([j '(1 2 3 4 5)])
        (for/list ([i '(1 2 3 4 5)])
          i)))
  > (pretty-print square)

  ((1 2 3 4 5)

   (1 2 3 4 5)

   (1 2 3 4 5)

   (1 2 3 4 5)

   (1 2 3 4 5))

  > (with-pretty-indent "..."
      (pretty-print square))

  ...((1 2 3 4 5)

  ... (1 2 3 4 5)

  ... (1 2 3 4 5)

  ... (1 2 3 4 5)

  ... (1 2 3 4 5))

(exn-context exn)  (listof symbol?)
  exn : exn?

Returns a printable form of the continuation marks of exn that can can be used with pretty-print to produce simple, legible debugging output.

(debug-in string require-spec)

require form that behaves like require-spec but prints the imported identifiers using debug.

(debug-out string require-spec)

provide form that behaves like provide-spec but prints the exported identifiers using debug.