▼ |  | Unstable: May Change Without Warning

1 | Guidelines for Developing unstable Libraries
2 | Automata: Compiling State Machines
3 | Bytes
4 | Contracts
5 | Contracts for Macro Subexpressions
6 | Debugging
7 | Definitions
8 | Errors
9 | Filesystem
10 | Find
11 | Flonums
12 | Futures
13 | Functions
14 | Hash Tables
15 | Interface-Oriented Programming for Classes
16 | Lazy Require
17 | Lists
18 | Logging
19 | Macro Testing
20 | Mark Parameters
21 | Match
22 | Open place expressions
23 | Options
24 | Parameter Groups
25 | Pretty-Printing
26 | Re-Contracting Identifiers
27 | Sandbox
28 | Sequences
29 | Strings
30 | Structs
31 | Struct Printing
32 | Syntax
33 | Temporal Contracts: Explicit Contract Monitors
34 | Unix Domain Sockets
35 | 2D Syntax
36 | GUI Libraries

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

5.3.6
top ← prev up next →

### 6`` Debugging

Carl Eastlund <cce@racket-lang.org>

This library is unstable; compatibility will not be maintained. See Unstable: May Change Without Warning for more information.

(require unstable/debug)

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

> > syntax

> > (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

> > procedure

> > (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:6.0: (dprintf "level: ~a" 1)
> level: 1
> result: #<void>
> << eval:6.0: (dprintf "level: ~a" 1)

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

> >> eval:7.0: (debug (dprintf "level: ~a" 2))
> >> eval:7.0: (dprintf "level: ~a" 2)
> level: 2
> result: #<void>
> << eval:7.0: (dprintf "level: ~a" 2)
> result: #<void>
> << eval:7.0: (debug (dprintf "level: ~a" 2))

> > syntax

> > (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:8.0: debugf
> >> eval:8.0: +
> result: #<procedure:+>
> << eval:8.0: +
> >> eval:8.0: 1
> result: 1
> << eval:8.0: 1
> >> eval:8.0: 2
> result: 2
> << eval:8.0: 2
> >> eval:8.0: 3
> result: 3
> << eval:8.0: 3
> result: 6
> << eval:8.0: debugf

> 6

> > syntax

> > (begin/debug expr ...)

> > syntax

> > (define/debug id expr)

> (define/debug (head args) body ...+)

> > syntax

> > (define/private/debug id expr)

> (define/private/debug (head args) body ...+)

> > syntax

> > (define/public/debug id expr)

> (define/public/debug (head args) body ...+)

> > syntax

> > (define/override/debug id expr)

> (define/override/debug (head args) body ...+)

> > syntax

> > (define/augment/debug id expr)

> (define/augment/debug (head args) body ...+)

> > syntax

> > (let/debug ([lhs-id rhs-expr] ...) body ...+)

> (let/debug loop-id ([lhs-id rhs-expr] ...) body ...+)

> > syntax

> > (let*/debug ([lhs-id rhs-expr] ...) body ...+)

> > syntax

> > (letrec/debug ([lhs-id rhs-expr] ...) body ...+)

> > syntax

> > (let-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

> > syntax

> > (let*-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

> > syntax

> > (letrec-values/debug ([(lhs-id ...) rhs-expr] ...) body ...+)

> > syntax

> > (with-syntax/debug ([pattern stx-expr] ...) body ...+)

> > syntax

> > (with-syntax*/debug ([pattern stx-expr] ...) body ...+)

> > syntax

> > (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.
top ← prev up next →