[plt-scheme] list building?

From: Mike (mikee at mikee.ath.cx)
Date: Wed May 4 09:43:24 EDT 2005

How is this handled? Read all lines (sexps in this case)
from a file, put the items in a list, then in another
(define) process the list.

When you read the file do you do this:

(define (load-tasks fp)
  (let ((task (read fp)))
    (if (eq? task eof)
      (list task (load-tasks fp)))))

so that at the end of the reading the resulting
list looks like '((task1) (task2) ())?

If so (or if not :), the processing (define)
is like:

(define (find-task id tasks)
  (let* ((task (car tasks))
         (num (assoc id task)))
    (if (number? num) task
      (find-task id (cdr tasks)))))

I get an error in that car expects a pair, but
is handed and empty list '().

What's the right way (tail recursion and all that)?


Posted on the users mailing list.