首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MIT-Scheme,有没有办法检查复合过程对象?

使用MIT-Scheme,有没有办法检查复合过程对象?
EN

Stack Overflow用户
提问于 2012-01-11 00:37:44
回答 1查看 2.1K关注 0票数 5

使用MIT-Scheme 9.x,有没有办法使用调试器或其他工具来检查匿名复合过程(通过返回lambda函数创建),例如找出它来自哪行的确切代码?

例如,我目前正在做的事情如下:

代码语言:javascript
复制
(foo 2 3)

我看到一条错误消息,如:

代码语言:javascript
复制
;The procedure #[compound-procedure 65] has been called with 2 arguments; it requires exactly 0 arguments.

...where foo正在做一些进一步的调度(foo不是这里的问题,它存在更深的问题)。在这个例子中,我真的很想知道#复合过程65的内部结构,因为它显然不是我所期望的。有没有Lisp/Scheme向导知道获取这些细节的方法?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-12 02:28:17

在这个页面上描述了一些有趣的调试工具:Debugging Aids

根据我尝试的简短实验,我认为您可以使用pp函数来检查复合过程对象的源代码:

代码语言:javascript
复制
1 ]=> (define (sum-squares x y) (+ (* x x) (* y y)))

;Value: sum-squares

1 ]=> (sum-squares 3)

;The procedure #[compound-procedure 13 sum-squares]
;has been called with 1 argument
;it requires exactly 2 arguments.
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

2 error> (pp #[compound-procedure 13 sum-squares])
(named-lambda (sum-squares x y)
  (+ (* x x) (* y y)))
;Unspecified return value

2 error> 

看起来您甚至可以获得lambda函数和已编译函数的源代码:

代码语言:javascript
复制
1 ]=> (define (make-acc-gen n) (lambda (i) (set! n (+ n i)) n))

;Value: make-acc-gen

1 ]=> (pp (make-acc-gen 0))
(lambda (i)
  (set! n (+ n i))
  n)
;Unspecified return value

1 ]=> display

;Value 15: #[compiled-procedure 15 ("output" #x16) #x1a #x101b23bd2]

1 ]=> (pp  #[compiled-procedure 15 ("output" #x16) #x1a #x101b23bd2])
(named-lambda (display object #!optional port environment)
  (let ((port (optional-output-port port 'display)))
    (unparse-object/top-level object port #f environment)
    ((%record-ref (%record-ref port 1) 14) port)))
;Unspecified return value

1 ]=> 

在链接的页面上还有其他一些有趣的反射工具。麻省理工学院方案也有一个bunch of stuff,用于处理环境,作为第一类对象,这对某些调试任务很有用。希望这能有所帮助!

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8806869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档