Subject: guile 2.0.6: "Value out of range: 0" when compiling a procedure

From: Feufochmar <[email-masked]>
Date: Sat, 11 Aug 2012 22:46:39 +0200

Hello,

guile 2.0.6 fails to compile the following procedure with the error "Value out of range: 0".

~~~~~~~

;; get all points inside a distance of the half-line starting from (x0 . y0) and containing (x1 . y1)
;; the argument dist is the square of the distance we want to reach
(define (get-half-line-points x0 y0 x1 y1 dist)
        (if (and (eq? x0 x1) (eq? y0 y1))
            (list (cons x0 y0))
            (letrec*
              ((steep? (> (abs (- y1 y0)) (abs (- x1 x0))))
               (x-orig (if steep? y0 x0))
               (y-orig (if steep? x0 y0))
               (x-dest (if steep? y1 x1))
               (y-dest (if steep? x1 y1))
               (delta-x (abs (- x-dest x-orig)))
               (delta-y (abs (- y-dest y-orig)))
               (delta-err (/ delta-y delta-x))
               (x-step (if (< x-orig x-dest) 1 -1))
               (y-step (if (< y-orig y-dest) 1 -1))
               (plot
                 (lambda (x y error points)
                         (if (< dist (+ (expt (- x x-orig) 2) (expt (- y y-orig) 2)))
                             (reverse points)
                             (let ((new-error (+ error delta-err)))
                                  (plot
                                    (+ x-step x)
                                    (if (>= new-error 0.5) (+ y y-step) y)
                                    (if (>= new-error 0.5) (- new-error 1) new-error)
                                    (cons (if steep? (cons y x) (cons x y)) points)))))))
              (plot x-orig y-orig 0 '()) )))

~~~~~~~

The backtrace I have with guild compile :

$ guild compile test.scm
Backtrace:
In language/tree-il/optimize.scm:
  44: 19 [optimize! #<tree-il (lambda () #)> #<module (#{ g40}#) 2097ab0> ...]
In language/tree-il/cse.scm:
 537: 18 [visit #<tree-il (lambda () (lambda-case #))> #<vlist ()> ...]
 543: 17 [visit #<tree-il (lambda-case (# #))> #<vhash 22cf540 1 pairs> ...]
 483: 16 [visit #<tree-il #> #<vhash 22cf540 1 pairs> #<vlist ()> ...]
 537: 15 [visit #<tree-il (lambda (#) (lambda-case #))> #<vhash 22cf540 1 pairs> ...]
 543: 14 [visit #<tree-il (lambda-case (# #))> #<vhash 22cf4a0 2 pairs> ...]
 429: 13 [visit #<tree-il (let # # # ...)> #<vhash 22cf4a0 2 pairs> #<vlist ()> ...]
 370: 12 [lp (#<tree-il (lambda () #)>) () #<vlist ()>]
 537: 11 [visit #<tree-il (lambda () (lambda-case #))> #<vhash 22cf4a0 2 pairs> ...]
 543: 10 [visit #<tree-il (lambda-case (# #))> #<vhash 22cf400 3 pairs> ...]
 437: 9 [visit #<tree-il (letrec* # # ...)> #<vhash 22cf400 3 pairs> ...]
 533: 8 [visit #<tree-il (apply # # ...)> #<vhash 23250e0 19 pairs> ...]
 370: 7 [lp (#<tree-il #> #<tree-il #> #<tree-il #> #<tree-il #>) () #<vlist ()>]
 533: 6 [visit #<tree-il (apply # #)> #<vhash 23250e0 19 pairs> ...]
 370: 5 [lp (#<tree-il (if # # #)>) () #<vlist ()>]
 403: 4 [return #<tree-il (if # # #)> #<vlist ()>]
 333: 3 [find-dominating-lexical #<tree-il (if # # ...)> 0 ...]
 315: 2 [unroll #<vhash 23250e0 19 pairs> 19 13]
In ice-9/vlist.scm:
 303: 1 [vlist-ref #<vhash 23250e0 19 pairs> 19]
In ice-9/boot-9.scm:
 106: 0 [#<procedure 204f280 at ice-9/boot-9.scm:97:6 (thrown-k . args)> out-of-range ...]

ice-9/boot-9.scm:106:20: In procedure #<procedure 204f280 at ice-9/boot-9.scm:97:6 (thrown-k . args)>:
ice-9/boot-9.scm:106:20: Value out of range: 0

Feufochmar