Sujet : Re: Newbie cluelessness continued...
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.schemeDate : 07. Jul 2025, 19:44:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <104h4ik$32a7p$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
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)))
Another way:
(define (file->lines file-name)
(with-input-from-file file-name
(lambda()
(collect-till line (read-line) (eof-object? line)))))
Given:
(define-syntax collect-till
(syntax-rules ()
[ (collect-till (x bag) expr test)
(collect-till (x bag) expr test #f) ]
[ (collect-till (x bag) expr test include-ender)
(let go ((bag '()))
(let ((x expr))
(if test
(if include-ender
(reverse (cons x bag))
(reverse bag))
(go (cons x bag))))) ]
[ (collect-till x expr test)
(collect-till (x bag) expr test) ]
[ (collect-till x expr test include-ender)
(collect-till (x bag) expr test include-ender) ] ))