title: Reading lines from file in Scheme (MIT/GNU Scheme)
body: <p>I am experimenting with Scheme (MIT/GNU Scheme 9.1) and I am writing some simple procedures to read and write files.</p>
  
  <p>In order to read all the lines contained in a file into a list I have written the following:</p>
  
  <pre><code>(define read-lines-from-port-impl
          (lambda (file-input-port)
                  (let* ((line (read-line file-input-port))
                        )
                        (if (eof-object? line)
                            (list)
                            (cons line (read-lines-from-port-impl file-input-port))
                        )
                  )
          )
  )
  
  
  (define read-lines-from-port
          (lambda (file-port)
                  (if (input-port? file-port)
                      (read-lines-from-port-impl file-port)
                      (list)
                  )
          )
  )
  
  
  (define read-lines-from-file
          (lambda (filename)
                  (call-with-input-file filename read-lines-from-port)
          )
  )
  </code></pre>
  
  <p><strong>Question 1</strong></p>
  
  <p>This seems to work but maybe there is a more idiomatic / concise way of doing
  this in Scheme. Can you suggest how to improve this code?</p>
  
  <p><strong>Question 2</strong></p>
  
  <p>In the above code I have used call-with-input-file which takes care of opening an
  input port before calling read-lines-from-port and of closing it after that procedure
  has completed.</p>
  
  <p>If I wanted to open and close an input port myself using open-input-file and close-input-port, how would I write this in Scheme? I mean I have to</p>
  
  <ul>
  <li>call open-input-file</li>
  <li>read the lines from the resulting port</li>
  <li>call close-input-port</li>
  </ul>
  
  <p>In Haskell i would use the do notation, but how do I specify such a sequence of actions in Scheme?</p>