[racket] how to trace stack by command line tools?

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Feb 2 14:28:49 EST 2012

> I have tried trace library but I have a problem.
> If I put my definitions in the interactive window, everything is fine.
> But if I put the definitions in the definition window and then I try to
> trace them, I get error "set!: cannot modify a constant: ".
> Why?

Let me assume you're doing something like this, that in Definitions,
you have something like this:

    #lang racket
    (require racket/trace)
    (define (f x) (* x x))

and in Interactions, you're trying to use trace:

    >  (trace f)

and you see an error at this point:

   set!: cannot modify a constant: ..

What's happening here is that the program in Definitions tries to
determine whether each definition is constant or not.  It doesn't see
that anything is changing 'f' inside Definitions, so it freezes the
definition.  Unfortunately, that means that you can't trace it.

Here's how to work around this:  you can add the following right after
a definition, such as f:

    #lang racket
    (require racket/trace)
    (define (f x) (* x x))
    (set! f f)

The set! there is a no-op, but it effectively tells Racket not to
enforce the constantness of f.  Then trace can be run on it from
Interactions.

Posted on the users mailing list.