<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Matthias Felleisen wrote:<br>
<blockquote cite="mid:76B051E0-732F-45E6-A9BC-888ED22DBB32@ccs.neu.edu"
type="cite">On Nov 4, 2008, at 9:52 AM, Shriram Krishnamurthi wrote:
<br>
<blockquote type="cite">Thanks, Robby.
<br>
<br>
1. It might be nice if someone w/ Cookbook access posted this version
<br>
w/ a comment about atomicity.
<br>
</blockquote>
<br>
Could someone explain why the cookbook uses an accumulator and reverse?
</blockquote>
I guess you are referring to this snippet? <br>
<br>
<tt>(define (readlines filename)<br>
(call-with-input-file filename<br>
(lambda (p)<br>
(let loop ((line (read-line p))<br>
(result '()))<br>
(if (eof-object? line)<br>
(reverse result)<br>
(loop (read-line p) (cons line result)))))))<br>
</tt><br>
But what would you use instead of an accumulator?<br>
<br>
The obvious solution<br>
<br>
<tt>(define (readlines filename)<br>
(call-with-input-file filename<br>
(lambda (p)<br>
(let loop ()<br>
(let ((line (read-line p)))<br>
(if (eof-object? line)<br>
'()<br>
(cons line (loop))))))))<br>
</tt><br>
breaks on implementations with a small stack.<br>
<tt><br>
</tt>-- <br>
Jens Axel Søgaard<br>
<br>
</body>
</html>