使用 trace 在球拍中显示一个过程 [英] Using trace to display a procedure in racket

查看:30
本文介绍了使用 trace 在球拍中显示一个过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在完成 SICP 的最后几个练习 ch 1,其中几个练习使用了高阶函数.目前,我正在尝试调试 1.45 解决方案中的一个问题,这会导致数量不匹配.引起误差的函数是对定点函数求解器两次应用平均运算的结果.

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.

如果我可以转储某种程序的表示,这将使我的调试工作轻松很多,因为该程序已经通过其他几个程序运行,这些程序在引发错误之前对其进行了更改.我查看了 DrRacket 的调试文档,将 (require racket/trace)(require errortrace) 添加到我的模块中,我想我熟悉所有调试系统的功能——但我仍然不知道如何做到这一点.

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.

DrRacket 的答案是理想的,但任何事情都有帮助.

An answer for DrRacket would be ideal, but anything helps.

推荐答案

添加(需要球拍/跟踪)不会在控制台中抛出任何程序显示.您想使用 (trace function-name) 这将在您在跟踪调用中使用给定函数时在控制台中打印紫色(默认颜色)行.例子

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. Example

(define sum (λ (x y) (+ x y)))
(define multiply
  (λ (x y)
    (multiply-aux x y x)
    ))
(define multiply-aux (λ (x y res) 
                       (if (= y 0) 0 
                           (if (= y 1) res 
                               (multiply-aux x (- y 1) (sum res x))))))
(require racket/trace)
(trace sum)

在控制台中:

> (multiply 4 5)
>(sum 4 4)
<8
>(sum 8 4)
<12
>(sum 12 4)

在 DrRacket 6.0.1 中测试

如果您需要更多帮助,请告诉我.

Let me know if you need more help.

这篇关于使用 trace 在球拍中显示一个过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆