我在slimv的帮助下通过vim调试以下mit方案程序。
(define (pascal x)
(define (pascal-iter m n max-len)
(cond ((and (> m 0) (> n 0))
(pascal-iter m (- n 1) max-len)
(beauti-print (pascal-item m n) max-len))
((= n 0) (pascal-iter (- m 1) (- m 1) max-len)
(display "\n")
(print-space (* (- x m) max-len)))
((= m 0) "Done")))
(define (pascal-item m n)
(cond ((= n 1) 1)
((= n m) 1)
(else (+ (pascal-item (- m 1) (- n 1))
(pascal-item (- m 1) n)))))
(define (beauti-print item max-len)
(print-space (floor (- max-len
(/ (num-of-digit item) 2))))
(display item)
(print-space (ceiling (- max-len
(/ (num-of-digit item) 2)))))
(define (num-of-digit n)
(+ (floor (/ (log n) (log 10))) 1) )
;; (print-space 1) -> " "
;; (print-space 1.5) -> " "
(define (print-space n)
(cond ((> n 0) (display " ")
(print-space (- n 1)))
(else (display ""))))
(pascal-iter x x (num-of-digit (pascal-item x (/ x 2)))))
(pascal 10)
当我运行命令:!mit-scheme --load "pascal.scm"
时,屏幕上会打印出一个pascal三角形,因此我无法发现程序中的任何错误。但是,当我执行,d
并尝试在slimv的REPL缓冲区中运行此程序时,我得到了:
(user)> (pascal 10)
; Evaluation aborted on <unknown reason>
(user)> (+ 40 2) ;; other statements are interpreted as expected
42
(user)>
那么,阻止我的程序正常运行的<unknown reason>
是什么?这是我的错,还是瘦身的错误?
这是swank.log
:
[-Received-] 0.481893
(:return (:abort "<unknown reason>") 8)
[Actionlist] 0.482347
8: finished :listener-eval
[---Sent---] 0.525237
(:emacs-rex (swank-repl:listener-eval "(pascal 12)
") "(user)" :repl-thread 9)