[gambit-list] I/O puzzle...

Marc Feeley feeley at iro.umontreal.ca
Tue Jun 9 23:10:28 EDT 2009


On 9-Jun-09, at 10:24 PM, Alex Queiroz wrote:

>>
>> Puzzle #2: why did Gambit chose to define timeouts that are not  
>> relative to
>> the moment that an I/O function is called?
>>
>
> I know this is ancient, but I missed the question when I first
> received the email. Well, why? :)
>

Because it does not work in the presence of abstraction.  Let's  
suppose that timeouts were relative to when the primitive is called  
and that the timeout is 3 seconds.  Then how would you write read-line  
so that the timeout will work consistently (that is, it will timeout 3  
seconds after the call to read-line)?

read-line cannot be written like this:

(define (read-line port)
   (let loop (...)
      ...
      (read-char port)
      ...
      (loop ...)))

because for each call to read-char a timeout of 3 seconds relative to  
that particular call to read-char will happen.  So, read-line will  
keep reading characters as long as the time between reading each char  
is less than 3 seconds.  So read-line can execute for arbitrarily  
long... it does not timeout 3 seconds after it is called.

Absolute timeouts eliminate this issue.

Marc




More information about the Gambit-list mailing list