Re: Reading a text file not line by line but at once (beginner)

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Reading a text file not line by line but at once (beginner)
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp
Date : 22. Jul 2024, 19:57:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v7m6hb$on7o$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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.
 
I like loop for this:
 
(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.

Date Sujet#  Auteur
22 Jul 24 * Re: Reading a text file not line by line but at once (beginner)3B. Pym
23 Jul 24 +- Re: Reading a text file not line by line but at once (beginner)1Kaz Kylheku
15 Aug 24 `- Re: Reading a text file not line by line but at once (beginner)1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal