I've been working through the last few exercises ch 1 of SICP, where several of the exercises uses higher-order functions. Currently I'm trying to debug a problem in my solution to 1.45, which is raising an arity mismatch. The function which is raising the error is the result of twice applying an averaging operation to a fixed-point function solver.
It would make my debugging efforts a lot easier if I could just dump some sort of representation of procedures, given that the procedure has been run through several other procedures that alter it before it raises an error. I've looked at the debugging documentation for DrRacket, added (require racket/trace)
and (require errortrace)
to my module and I think I'm familiar with the all the features of the debugging system -- but I still have no idea how to do this.
An answer for DrRacket would be ideal, but anything helps.
One trick is to create an alias for a primitive function. So if you want to trace the addition operator somewhere, trace won't allow it unless you do this:
(require trace) (define *+ +)
Then use *+ anywhere in the code where you want to watch its output closely, without seeing the output of + used elsewhere.
Adding (require racket/trace) won't throw any procedure displays in the console. You want to use
(trace function-name)
this will print purple (default color) lines in the console when you use the given function in the trace call. ExampleIn the console:
Tested in DrRacket 6.0.1
Let me know if you need more help.