Discussion:
Reading a text file not line by line but at once (beginner)
(too old to reply)
B. Pym
2024-07-22 17:57:00 UTC
Permalink
I have a file which consists of one word per line and I would like to
read it into a single list.
Searching the web[1] I found something which I adapted to my
needs. Basically the code works but it is terribly inefficient. This
is not the fault of the CL Cookbook. Probably I am using a hammer as a
screwdriver.
I'd be happy if you can give me some directions how I can tackle the
problem in a better way.
(with-open-file (s "foo.txt" :direction :input)
(loop for line = (read-line s nil)
while line
collect line))
Gauche Scheme

(use gauche.generator)

(with-input-from-file "temp.txt"
(cut generator->list read-line))


Paul Graham, May 2001:

A hacker's language is terse and hackable. Common Lisp is not.

The good news is, it's not Lisp that sucks, but Common Lisp.
Kaz Kylheku
2024-07-23 01:20:00 UTC
Permalink
Post by B. Pym
I have a file which consists of one word per line and I would like to
read it into a single list.
Searching the web[1] I found something which I adapted to my
needs. Basically the code works but it is terribly inefficient. This
is not the fault of the CL Cookbook. Probably I am using a hammer as a
screwdriver.
I'd be happy if you can give me some directions how I can tackle the
problem in a better way.
(with-open-file (s "foo.txt" :direction :input)
(loop for line = (read-line s nil)
while line
collect line))
Gauche Scheme
(use gauche.generator)
(with-input-from-file "temp.txt"
(cut generator->list read-line))
A hacker's language is terse and hackable. Common Lisp is not.
The good news is, it's not Lisp that sucks, but Common Lisp.
TXR Lisp:

(file-get-lines "temp.txt")
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @***@mstdn.ca
B. Pym
2024-08-14 22:46:26 UTC
Permalink
Post by B. Pym
I have a file which consists of one word per line and I would like to
read it into a single list.
Searching the web[1] I found something which I adapted to my
needs. Basically the code works but it is terribly inefficient. This
is not the fault of the CL Cookbook. Probably I am using a hammer as a
screwdriver.
I'd be happy if you can give me some directions how I can tackle the
problem in a better way.
(with-open-file (s "foo.txt" :direction :input)
(loop for line = (read-line s nil)
while line
collect line))
Gauche Scheme
(use gauche.generator)
(with-input-from-file "temp.txt"
(cut generator->list read-line))
A hacker's language is terse and hackable. Common Lisp is not.
The good news is, it's not Lisp that sucks, but Common Lisp.
newLISP

(let (h (open "output.dat" "read"))
(println (collect (read-line h)))
(close h))

("foo 0" "2 4 6" "8 9")

Loading...