Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You have an ability to sense and know higher truth.


comp / comp.lang.lisp / Re: Reading a text file not line by line but at once (beginner)

SubjectAuthor
* Re: Reading a text file not line by line but at once (beginner)B. Pym
+- Re: Reading a text file not line by line but at once (beginner)Kaz Kylheku
`- Re: Reading a text file not line by line but at once (beginner)B. Pym

1
Subject: Re: Reading a text file not line by line but at once (beginner)
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 22 Jul 2024 17:57 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Reading a text file not line by line but at once (beginner)
Date: Mon, 22 Jul 2024 17:57:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <v7m6hb$on7o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Mon, 22 Jul 2024 19:57:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="9bd2863663604f2e05c19a8ebb644b33";
logging-data="810232"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XplvQySLSBzCRnGlvjUis"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:VPrPlt67kPsKcfqpvjqRa6xQK+U=
View all headers

> > 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.

Subject: Re: Reading a text file not line by line but at once (beginner)
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Tue, 23 Jul 2024 01:20 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Reading a text file not line by line but at once (beginner)
Date: Tue, 23 Jul 2024 01:20:00 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <20240722181451.984@kylheku.com>
References: <v7m6hb$on7o$1@dont-email.me>
Injection-Date: Tue, 23 Jul 2024 03:20:00 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2e723cea1cdfb5e1d326eb8834436c3e";
logging-data="950529"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bfr3qR0WUrgkz9Yd5OCCSuhzU/MLCMVY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:weBqTP5qwKF0761YKHneg0C6+uk=
View all headers

On 2024-07-22, B. Pym <Nobody447095@here-nor-there.org> wrote:
>> > 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.

TXR Lisp:

(file-get-lines "temp.txt")

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: Reading a text file not line by line but at once (beginner)
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 14 Aug 2024 22:46 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Reading a text file not line by line but at once (beginner)
Date: Wed, 14 Aug 2024 22:46:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <v9jc40$kngb$1@dont-email.me>
References: <v7m6hb$on7o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 15 Aug 2024 00:46:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="8dd797abfa9c4845a90c0b3910c2697b";
logging-data="679435"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18S7fSV3RQR3zfbqNLB7pNn"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pDy7ToY/4oYP7G3ldlbfCQcR3HA=
View all headers

B. Pym wrote:

> > > 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.

newLISP

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

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

1

rocksolid light 0.9.8
clearnet tor