HTDP Trace
define/  trace
8.12

HTDP Trace🔗ℹ

djholtby

 (require htdp-trace) package: htdp-trace

Racket has a useful tracing tool. Unfortunately it does not work in Beginning Student. This package provides a wrapper that can be used in the HtDP Languages.

syntax

(define/trace (name param ...) body)

Behaves the same as define, but whenever the function name is applied, the values of its parameters will be printed to the screen. When the function produces a value, that value will also be printed.

Examples:
(require htdp-trace)
(define/trace (f x)
 (+ 2 x))
(f 2)

>(f 2)

<4

4

(define/trace (sum-nums n)
 (cond [(zero? n) 0]
       [else (+ n (sum-nums (- n 1)))]))
(sum-nums 3)

>(sum-nums 3)

> (sum-nums 2)

> >(sum-nums 1)

> > (sum-nums 0)

< < 0

< <1

< 3

<6

6