(define-syntax list-ofThe stream SRFI is best discussed on the post-finalization discussion list of the SRFI itself. But since you asked here, I'll answer here, and send a copy to the SRFI.
(syntax-rules (range in is)
((_ "aux" expr base)
(cons expr base))
((_ "aux" expr base (x range first past step) clauses ...)
(let ((more? (if (positive? step) < >)))
(let loop ((z first))
(if (more? z past)
(let ((x z))
(list-of "aux" expr (loop (+ z step)) clauses ...))
base))))
((_ "aux" expr base (x range first past) clauses ...)
(let* ((step (if (< first past) 1 -1))
(more? (if (positive? step) < >)))
(let loop ((z first))
(if (more? z past)
(let ((x z))
(list-of "aux" expr (loop (+ z step)) clauses ...))
base))))
((_ "aux" expr base (x in xs) clauses ...)
(let loop ((z xs))
(if (null? z)
base
(let ((x (car z)))
(list-of "aux" expr (loop (cdr z)) clauses ...)))))
((_ "aux" expr base (x is y) clauses ...)
(let ((x y))
(list-of "aux" expr base clauses ...)))
((_ "aux" expr base pred? clauses ...)
(if pred?
(list-of "aux" expr base clauses ...)
base))
((_ expr clauses ...)
(define-syntax fold-of
(syntax-rules (range in is)
((_ "aux" op base expr)
(op expr base))
((_ "aux" op base expr (x range first past step) clauses ...)
(let ((more? (if (positive? step) < >)))
(let loop ((z first))
(if (more? z past)
(let ((x z))
(fold-of "aux" op (loop (+ z step)) expr clauses ...))
base))))
((_ "aux" op base expr (x range first past) clauses ...)
(let* ((step (if (< first past) 1 -1))
(more? (if (positive? step) < >)))
(let loop ((z first))
(if (more? z past)
(let ((x z))
(fold-of "aux" op (loop (+ z step)) expr clauses ...))
base))))
((_ "aux" op base expr (x in xs) clauses ...)
(let loop ((z xs))
(if (null? z)
base
(let ((x (car z)))
(fold-of "aux" op (loop (cdr z)) expr clauses ...)))))
((_ "aux" op base expr (x is y) clauses ...)
(let ((x y))
(fold-of "aux" op base expr clauses ...)))
((_ "aux" op base expr pred? clauses ...)
(if pred?
(fold-of "aux" op base expr clauses ...)
base))
((_ op base expr clauses ...)
(fold-of "aux" op base expr clauses ...))))
(list-of "aux" expr '() clauses ...))))
On Apr 4, 4:49 pm, "Phil Bewig" <pbe...@xxxxxxxxx> wrote:
> You might find some useful ideas for processing csv files here:
>
> schemephil.googlepages.com/TextFileDatabases.pdf
>
> Phil
That was very instructive thanks. Do you plan to submit the CSV
library as an SRFI?
BTW, I take the opportunity to ask you a few questions about the
streams
SRFI (not sure if this is the proper forum but, oh well!).
I really really like the streams library and especially the
stream-comprehension syntax (I have even adapted it for lists).
Still, I have some question.
First of all, I don't see the point of port->stream. As soon you
introduce it, you say that it does not work as expected and you give a
recipe for converting files in streams:
(define-stream (file->stream filename)
(let ((p (open-input-file filename)))
(stream-let loop ((c (read-char p)))
(if (eof-object? c)
(begin (close-input-port p)
stream-null)
(stream-cons c
(loop (read-char p)))))))
Why not to put file->stream directly in the library? When should I use
port->stream? Also, suppose there is a read error at some point. Can I
assume that the port will be closed properly? It does not look so from
the code. Also, for text files a file->stream function returning lines
would be much more useful than a function returning characters.
Final question: why stream-equal? is given as a recipe but not
included in the library? It seems useful enough to be included.
Ok, that was a lot of questions, but bear with me ;)
Michele Simionato