Welcome to the CHICKEN Scheme pasting service

Read csv added by eesslan on Sun Mar 9 14:56:57 2014

(define (read-csv fn port #!key (delim ",") (skip 0) (n #f))
  ;; skip first 'skip' lines                                                    
  (let loop ((i skip))
    (unless (zero? i)
      (read-line port)
      (loop (sub1 i))))
  (let ((splitter (lambda (x) (string-split x delim #t))))
    (if n
        ;; read at most n lines after 'skip' lines                              
        (let loop ((line (read-line port))
                   (n n))
          (unless (or (zero? n) (eof-object? line))
            (fn (splitter line))
            (loop (read-line port) (sub1 n))))
        (let loop ((line (read-line port)))
          (unless (eof-object? line)
             (fn (splitter line))
             (loop (read-line port)))))))

(call-with-input-file "bookvalue.csv"
  (lambda (iport)
    (read-csv print iport skip: 1 n: 20)))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the equality predicate for strings in R5RS?
Visually impaired? Let me spell it for you (wav file) download WAV