0

I'm debugging the following mit-scheme program through vim with the assistance of slimv.

(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)

When I ran the command :!mit-scheme --load "pascal.scm", a pascal triangle is printed on the screen, so there I can't spot any bug in my program. However, when I executed ,d and tried to run this program in slimv's REPL buffer, I got:

(user)> (pascal 10)
; Evaluation aborted on <unknown reason>
(user)> (+ 40 2) ;; other statements are interpreted as expected
42
(user)> 

So, what's the <unknown reason> that prevents my program from running properly? Is it my fault, or a bug of slimv?

This is the relevant part of 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)
nalzok
  • 14,965
  • 21
  • 72
  • 139
  • You can enable the logging of the communication between slimv and the swank server by adding this line to your `.vimrc`: `let g:swank_log = 1`, then a `swank.log` file will be generated in your working directory. Please check the tail of the log file. The "Evaluation aborted" message is printed by slimv if the swank server responds with an `:abort` message (instead of the normal `:ok` message). I tried to run your example in my slimv session and it successfully executed and printed the pascal triangle into the REPL window, so I could not reproduce your problem. – Tamas Kovacs Nov 18 '16 at 14:11
  • @TamasKovacs I've done what you've said, and the log says...`(:return (:abort "") 8)` If you can't reproduce this problem, try `(pascal 11)` or `(pascal 12)`. On my machine, at this moment, `(pascal 10)` and `(pascal 12)` computes well, while evaluating `(pascal 11)` throws an error. – nalzok Nov 18 '16 at 14:22
  • @TamasKovacs My guess would be swank quited because maximum recursion depth was exceeded. Anyway, recursion is very expensive, and there are two nested recursive process in this code. – nalzok Nov 18 '16 at 14:33
  • Ah, yes, I could reproduce it with `(pascal 11)`. All I can see is the same abort message you described. That is something the swank server sends to slimv in response of a `listener-eval` request. I'm afraid I can't tell the reason, I'm not a swank expert, but I agree with you: it may be related with the recursion depth. – Tamas Kovacs Nov 18 '16 at 14:37

0 Answers0