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

lim*_*ist 5 lisp debugging scheme mit-scheme

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

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

(foo 2 3)
Run Code Online (Sandbox Code Playgroud)

我看到一条错误消息:

;The procedure #[compound-procedure 65] has been called with 2 arguments; it requires exactly 0 arguments.
Run Code Online (Sandbox Code Playgroud)

... foo正在进行一些进一步的调度(foo不是问题,它更深层次).在这个例子中,我真的想知道#[compound-procedure 65]的内部结构,因为它显然不是我的预期.Lisp/Scheme向导是否知道获取这些细节的方法?谢谢.

mic*_*kig 7

本页描述了一些有趣的调试工具:调试辅助工具.

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

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> 
Run Code Online (Sandbox Code Playgroud)

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

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 ]=> 
Run Code Online (Sandbox Code Playgroud)

链接页面上还有一些其他有趣的反射工具.麻省理工学院计划也有一堆东​​西用于搞乱环境作为第一类对象,这对某些调试任务很有用.希望有所帮助!

  • 更短:(pp#@ 42),其中42是程序号. (4认同)