guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Do-loop enigma with two variables


From: Pierre Lairez
Subject: Re: Do-loop enigma with two variables
Date: Fri, 15 Jul 2016 20:49:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

I use v2.0.11 on ubuntu and the behavior is the same with the packaged
version or the one compiled from source. It is hard to believe that
there is a bug in “letrec” and “lambda”...

Pierre

On 15/07/2016 20:24, Nala Ginrut wrote:
> 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
>>


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]