[plt-scheme] Useless abstraction? HtDP 27.2.2

From: Horace Dynamite (horace.dynamite at googlemail.com)
Date: Wed May 12 15:52:55 EDT 2010

Dear reader,

I am having terrible difficulties understanding the point of
abstraction in exercise 27.2.2 of HtDP. Please see below my answer to
this exercise. I get correct output for my example input, but the
definition seems more complicated than the original. Can anyone guide
me on where I'm going wrong? I just cannot see a more suitable
abstraction. I followed the abstraction recipe diligently.

;; file>-list-of-lines:abs : file -> (listof (listof symbol))
;; to convert a file into a list of lines. Abstracted version.
(define (file->list-of-lines afile)
  (local [(define NEWLINE 'NL)
          (define (extract-from-file afile termination combination)
              [(empty? afile) empty]
              [else (cond
                      [(symbol=? (first afile) NEWLINE) termination]
                      [else (combination (rest afile))])]))
          (define (first-line afile)
            (extract-from-file afile
                               (lambda (x) (cons (first afile)
(first-line x)))))
          (define (remove-first-line afile)
            (extract-from-file afile
                               (rest afile)
                               (lambda (x) (remove-first-line x))))]
      [(empty? afile) empty]
       (cons (first-line afile)
             (file->list-of-lines (remove-first-line afile)))])))

Thank you for your time.


Posted on the users mailing list.