Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 23 |
Nodes: | 6 (0 / 6) |
Uptime: | 52:41:03 |
Calls: | 583 |
Files: | 1,139 |
D/L today: |
179 files (27,921K bytes) |
Messages: | 111,617 |
(with-open-file (...)
(loop for line = (read-line stream nil stream)
until (eql line stream)
collect line))
Tim Bradshaw wrote:
(with-open-file (...)
(loop for line = (read-line stream nil stream)
until (eql line stream)
collect line))
Gauche Scheme
(use srfi-42) ;; list-ec
(call-with-input-file "data.bak"
(lambda (port)
(list-ec (:port line port read-line) line)))
speaking of basic tools i would prefer using do rather when loop
(which IMHO is quite "unlispish") like:
(defun read-file (arg-file-name)
(with-open-file (stream arg-file-name :direction :input)
(do ((line nil (read-line stream nil stream))
(r nil (push line r)))
((eql line stream) (cdr (nreverse r))))))
Tim Bradshaw wrote:
(with-open-file (...)
(loop for line = (read-line stream nil stream)
until (eql line stream)
collect line))
Gauche Scheme
(use srfi-42) ;; list-ec
(call-with-input-file "data.bak"
(lambda (port)
(list-ec (:port line port read-line) line)))
B. Pym wrote:
Tim Bradshaw wrote:
(with-open-file (...)
(loop for line = (read-line stream nil stream)
until (eql line stream)
collect line))
Gauche Scheme
(use srfi-42) ;; list-ec
(call-with-input-file "data.bak"
(lambda (port)
(list-ec (:port line port read-line) line)))
Sascha Wilde wrote:
speaking of basic tools i would prefer using do rather when loop
(which IMHO is quite "unlispish") like:
(defun read-file (arg-file-name)
(with-open-file (stream arg-file-name :direction :input)
(do ((line nil (read-line stream nil stream))
(r nil (push line r)))
Should have used cons instead of push.
((eql line stream) (cdr (nreverse r))))))
The cdr removes the bogus first element (nil).
Scheme
(define (file->lines file-name)
(with-input-from-file file-name
(lambda()
(do ((line #f (read-line))
(r '() (cons line r)))
((eof-object? line) (cdr (reverse r)))))))