(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)))))
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)))
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:23:27 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,603 |