Sujet : Re: Reading data into list from "include" file
De : NoSpam_762 (at) *nospam* not_there.org (B. Pym)
Groupes : comp.lang.lispDate : 10. Jul 2024, 18:13:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6mbui$1vpsc$1@dont-email.me>
References : 1 2 3
User-Agent : XanaNews/1.18.1.6
Raymond Wiker wrote:
For people who don't like extended loop, I think this a better
implementation:
(defun read-numbers-from-file/2 (file-path n)
(with-open-file (f file-path :direction :input)
(let ((res nil))
(dotimes (i n)
(push (parse-integer (read-line f nil)) res))
(nreverse res))))
Gauche Scheme
(with-input-from-file "output.dat"
(lambda res
(until (read) eof-object? => x
(push! res x))
(reverse res)))
===>
(4 3 2 1 3 4 2 1 4 2 3 1 2 4 3 1 3 2 4 1 2 3 4 1 4 3 1 2
3 4 1 2 4 1 3 2 1 4 3 2 3 1 4 2 1 3 4 2 4 2 1 3 2 4 1 3
4 1 2 3 1 4 2 3 2 1 4 3 1 2 4 3 3 2 1 4 2 3 1 4 3 1 2 4
1 3 2 4 2 1 3 4 1 2 3 4)