2012-01-10 39 views
5

使用MIT-Scheme 9.x,有沒有一種方法使用調試器或其他工具來檢查匿名複合過程(通過返回lambda函數創建)找出來自哪一行的確切代碼?使用MIT-Scheme,有沒有辦法檢查複合過程對象?

例如,我正在做這樣的事情:

(foo 2 3) 

而且我看到一個錯誤信息,如:

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

...其中foo是做一些進一步的調度(foo是不是這裏的問題,它更深層)。在這個例子中,我真的很想知道#[複合過程65]的內部結構,因爲它顯然不是我所期望的。在那裏的Lisp/Scheme嚮導是否知道獲取這些細節的方法?謝謝。

回答

7

本頁描述了一些有趣的調試工具:Debugging Aids

從短期實驗我試過了,我想你可以使用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 ]=> 

在鏈接頁面上還有一些其他有趣的反射工具。麻省理工學院計劃也有一個bunch of stuff與環境作爲一流的對象,可用於某些調試任務。希望有所幫助!

+0

是的,這有助於很多 - 正是需要的! – limist 2012-01-12 17:40:58

+4

甚至更​​短:(pp#@ 42),其中42是程序編號。 – limist 2012-01-12 18:35:58

相關問題