On this page:
debug
dprintf
debugf
begin/ debug
define/ debug
define/ private/ debug
define/ public/ debug
define/ override/ debug
define/ augment/ debug
let/ debug
let*/ debug
letrec/ debug
let-values/ debug
let*-values/ debug
letrec-values/ debug
with-syntax/ debug
with-syntax*/ debug
parameterize/ debug
Version: 5.0.1

43 Debugging

Carl Eastlund <cce@racket-lang.org>

 (require unstable/debug)

This library is unstable; compatibility will not be maintained. See Unstable for more information.

This module provides macros and functions for printing out debugging information.

(debug options ... expr)
 
options = #:name name-expr
  | #:source srcloc-expr
Writes debugging information about the evaluation of expr to the current error port. The name and source location of the expression may be overridden by keyword options; their defaults are the syntactic form of the expression and its syntactic source location, respectively.

Examples:

  > (debug 0)

  >> eval:2.0: 0

    result: 0

  << eval:2.0: 0

  0

  > (debug #:name "one, two, three" (values 1 2 3))

  >> eval:3.0: "one, two, three"

    results: (values 1 2 3)

  << eval:3.0: "one, two, three"

  1

  2

  3

  > (debug #:source (make-srcloc 'here 1 2 3 4)
      (error 'function "something went wrong"))

  >> here:1.2: (error 'function "something went wrong")

    raised exception: function: something went wrong

  << here:1.2: (error 'function "something went wrong")

  function: something went wrong

(dprintf fmt arg ...)  void?
  fmt : string?
  arg : any/c
Constructs a message in the same manner as format and writes it to (current-error-port), with indentation reflecting the number of nested debug forms.

Examples:

  > (dprintf "level: ~a" 0)

  level: 0

  > (debug (dprintf "level: ~a" 1))

  >> eval:3.0: (dprintf "level: ~a" 1)

    level: 1

    result: #<void>

  << eval:3.0: (dprintf "level: ~a" 1)

  > (debug (debug (dprintf "level: ~a" 2)))

  >> eval:4.0: (debug (dprintf "level: ~a" 2))

    >> eval:4.0: (dprintf "level: ~a" 2)

      level: 2

      result: #<void>

    << eval:4.0: (dprintf "level: ~a" 2)

    result: #<void>

  << eval:4.0: (debug (dprintf "level: ~a" 2))

(debugf function-expr argument ...)
 
argument = argument-expr
  | argument-keyword argument-expr
Logs debugging information for (#%app function-expr argument ...), including the evaluation and results of the function and each argument.

Example:

  > (debugf + 1 2 3)

  >> eval:2.0: debugf

    >> eval:2.0: +

      result: #<procedure:+>

    << eval:2.0: +

    >> eval:2.0: 1

      result: 1

    << eval:2.0: 1

    >> eval:2.0: 2

      result: 2

    << eval:2.0: 2

    >> eval:2.0: 3

      result: 3

    << eval:2.0: 3

    result: 6

  << eval:2.0: debugf

  6

(begin/debug expr ...)
(define/debug id expr)
(define/debug (head args) body ...+)
(define/private/debug id expr)
(define/private/debug (head args) body ...+)
(define/public/debug id expr)
(define/public/debug (head args) body ...+)
(define/override/debug id expr)
(define/override/debug (head args) body ...+)
(define/augment/debug id expr)
(define/augment/debug (head args) body ...+)
(let/debug ([lhs-id rhs-expr] ...) body ...+)
(let/debug loop-id ([lhs-id rhs-expr] ...) body ...+)
(let*/debug ([lhs-id rhs-expr] ...) body ...+)
(letrec/debug ([lhs-id rhs-expr] ...) body ...+)
(let-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)
(let*-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)
(letrec-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)
(with-syntax/debug ([pattern stx-expr] ...) body ...+)
(with-syntax*/debug ([pattern stx-expr] ...) body ...+)
(parameterize/debug ([param-expr value-expr] ...) body ...+)
These macros add logging based on debug to the evaluation of expressions in begin, define, define/private, define/public, define/override, define/augment, let, let*, letrec, let-values, let*-values, letrec-values, with-syntax, with-syntax*, and parameterize.