Home  |   Notes  |   Languages  |   Programs  |   Homework

Re: Displaying return values in test data?

New Message Reply About this list Date view Thread view Subject view Author view

Stephen Edwards (edwards@CS.VT.EDU)
Wed, 24 Oct 2001 10:49:48 -0400


Message-ID:  <3BD6D50C.CAB641A8@cs.vt.edu>
Date:         Wed, 24 Oct 2001 10:49:48 -0400
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: Displaying return values in test data?

The easiest way is to execute this command:

    (trace-exit JVM-interpret)

Then every time this function returns from an invocation, you will see
a diagnostic message showing both the arguments that were used and the
return value (Section 5 of th Scheme User's Manual: "Debugging").

Alternatively, since this is a functional language, you can add
this feature yourself.

Suppose your code originally looked like this:

(define (func args)
    (... body ...)
)

Here, the body could be something really large.

All you need to do is modify your function definition a bit:

(define (func args)
    (let ((result ; A temporary name for the real return val

           (... body ...) ; Capture the result from executing body

         ))

        ; Now print the result:
        (display "func result => ")
        (display result)
        (newline)

        ; and finally, let result be the value produced by the let
        result
    )
)

If you do this yourself, you can simply comment out the new
lines you've added around (... body ...) once you no longer need
tracing abilities. Effectively, the trace-exit command has
almost exactly the same effect, but is easier to do.

BTW, there is also a trace-entry command (print a message w/
arg values on entry to a function) and a trace-both command
(trace-entry + trace-exit on the same function) if you are
trying to follow the flow of execution in your code.

                                -- Steve

--
Stephen Edwards            604 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------


New Message Reply About this list Date view Thread view Subject view Author view

Home  |   Notes  |   Languages  |   Programs  |   Homework
copyright © 2001 Virginia Tech, ALL RIGHTS RESERVED
Class site maintained by Stephen H. Edwards <edwards@cs.vt.edu>