[plt-scheme] reading a whole file

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Tue Nov 4 10:59:02 EST 2008

Matthias Felleisen wrote:
>
> On Nov 4, 2008, at 10:39 AM, Jens Axel Soegaard wrote:
>
>> The obvious solution
>>
>> (define (readlines filename)
>>   (call-with-input-file filename
>>     (lambda (p)
>>       (let loop ()
>>         (let ((line (read-line p)))
>>           (if (eof-object? line)
>>               '()
>>               (cons line (loop))))))))
>>
>> breaks on implementations with a small stack.
>
> I don't know what those implementations implement but it's certainly 
> not Scheme :-)
Well, the recursive call to loop is not in tail-call position, and there 
is no guarantee
on the upper bound of the number of active calls in RnRS, so this could
become a problem in simple implementations (for example implementations
that use inherit the a maximum stack size from C).

-- 
Jens Axel Søgaard



Posted on the users mailing list.