Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/debugging/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Debugging 使用MIT方案,是否有方法检查复合过程对象?_Debugging_Lisp_Scheme_Mit Scheme - Fatal编程技术网

Debugging 使用MIT方案,是否有方法检查复合过程对象?

Debugging 使用MIT方案,是否有方法检查复合过程对象?,debugging,lisp,scheme,mit-scheme,Debugging,Lisp,Scheme,Mit Scheme,使用MIT Scheme 9.x,是否有办法使用调试器或其他工具检查匿名复合过程(通过返回lambda函数创建),例如,找出它来自哪一行的确切代码 例如,我目前正在做如下工作: (foo 2 3) 我看到一条错误消息,如: ;The procedure #[compound-procedure 65] has been called with 2 arguments; it requires exactly 0 arguments. …在这里,foo正在做一些进一步的调度(foo不是这里的问

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

例如,我目前正在做如下工作:

(foo 2 3)
我看到一条错误消息,如:

;The procedure #[compound-procedure 65] has been called with 2 arguments; it requires exactly 0 arguments.

…在这里,foo正在做一些进一步的调度(foo不是这里的问题,而是更深层次的问题)。在这个例子中,我真的很想知道#[复合过程65]的内部结构,因为它显然不是我所期望的。Lisp/Scheme向导知道获取这些详细信息的方法吗?谢谢。

本页介绍了一些有趣的调试工具:

根据我尝试的简短实验,我认为可以使用
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> 
您甚至可以获得
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 ]=> 

链接页面上还有其他一些有趣的反射工具。MIT方案还提供了一个将环境作为第一类对象处理的方法,这对于某些调试任务非常有用。希望有帮助

是的,这很有帮助-正是我们所需要的!甚至更短:(pp#@42),其中42是程序编号。