Obviously there's bug in your Guile, I'm using the latest 2.1.3.59- 516f7 and it's fine. It's suspended for Guile-2.0 branch, anyone give it a test?
On Fri, 2016-07-15 at 16:26 +0200, Pierre Lairez wrote: > Dear guile users, > > When running the following loop: > (do ((i 1 (+ 1 i)) > (j 0 i)) > ((> i 4) (newline)) > (display (list i j))) > > I expect without hesitation to read > (1 0)(2 1)(3 2)(4 3) > > To my surprise, I obtain > (1 0)(2 2)(3 3)(4 4) > > After macro-expansion, the loop above is rewritten in the following: > (letrec ((loop > (λ (i j) > (if (> i 4) > (newline) > (begin > (display (list i j)) > (loop (+ 1 i) i)))))) > (loop 1 0)) > > The equality j = i + 1 is clearly a loop invariant, the function > “loop“ > is *never* called with two equal arguments. So I cannot understand > why > (2 2) may possibly appear in the output. What do I not see? > > Best regards, > > Pierre >
