Sujet : Re: Style question
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 30. Jun 2025, 11:07:19
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <103tnkl$240ld$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
B. Pym wrote:
Rob Warnock wrote:
(defun file-forms (path)
"Sucks up an entire file from PATH into a list of forms (sexprs),
returning two values: the list of forms and the number of forms read."
(with-open-file (s path)
(loop with eof = (list :eof)
for form = (read s nil eof)
until (eq form eof)
collect form into forms
counting t into form-count
finally (return (values forms form-count)))))
Gauche Scheme
(use srfi-42) ;; list-ec
(define (file-forms file)
(let ((count 0))
(values
(call-with-input-file file
(lambda (inport)
(list-ec
(:port form inport read)
(begin (inc! count))
form)))
count)))
Gauche Scheme
(define (file-forms file)
(with-input-from-file file
(lambda()
(do ((x #f)
(forms () (cons x forms))
(i 0 (+ 1 i)))
((eof-object? (set! x (read)))
(values (reverse forms) i))))))