Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

A visit to a strange place will bring fresh work.


comp / comp.lang.lisp / Re: Reading data into list from "include" file

SubjectAuthor
* Re: Reading data into list from "include" fileB. Pym
`* Re: Reading data into list from "include" fileB. Pym
 `- Re: Reading data into list from "include" fileB. Pym

1
Subject: Re: Reading data into list from "include" file
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Wed, 10 Jul 2024 16:13 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: NoSpam_762@not_there.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Reading data into list from "include" file
Date: Wed, 10 Jul 2024 16:13:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <v6mbui$1vpsc$1@dont-email.me>
References: <87a5q7gzm1.fsf@axel-reichert.de> <XPVFq67p4V6ivNUR3@bongo-ra.co> <m2y1dqrxt7.fsf@MacBook-Pro-2.home>
Injection-Date: Wed, 10 Jul 2024 18:13:09 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="6f6282e3be4159d4eef0e2cf40c4caf3";
logging-data="2090892"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A7nWKc7fAJaRzIIa5ZEzS"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:pyQ65iv+ktHRj64WI96L4hPa5cY=
View all headers

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)

Subject: Re: Reading data into list from "include" file
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 11 Jul 2024 10:46 UTC
References: 1 2 3 4
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 data into list from "include" file
Date: Thu, 11 Jul 2024 10:46:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v6od6u$2e0tq$1@dont-email.me>
References: <87a5q7gzm1.fsf@axel-reichert.de> <XPVFq67p4V6ivNUR3@bongo-ra.co> <m2y1dqrxt7.fsf@MacBook-Pro-2.home> <v6mbui$1vpsc$1@dont-email.me>
Injection-Date: Thu, 11 Jul 2024 12:46:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="edbd767bc3b23e42808c9cefad3fb6bd";
logging-data="2556858"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6XFPMH0p51IFbW7GyOgKr"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:A5JDP7wB4lt3t8tI/TKrfvwLX8w=
View all headers

B. Pym wrote:

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

(define (collect-till pred gen key)
(do ((x (gen) (gen))
(res '() (cons x res)))
((pred x) (reverse res))))

(with-input-from-file "output.dat"
(lambda _
(collect-till eof-object? read +)))

Subject: Re: Reading data into list from "include" file
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 11 Jul 2024 16:01 UTC
References: 1 2 3 4 5
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 data into list from "include" file
Date: Thu, 11 Jul 2024 16:01:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <v6ovk8$2he6l$1@dont-email.me>
References: <87a5q7gzm1.fsf@axel-reichert.de> <XPVFq67p4V6ivNUR3@bongo-ra.co> <m2y1dqrxt7.fsf@MacBook-Pro-2.home> <v6mbui$1vpsc$1@dont-email.me> <v6od6u$2e0tq$1@dont-email.me>
Injection-Date: Thu, 11 Jul 2024 18:01:13 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="456461bd00b90f08114198f185f05762";
logging-data="2668757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Bxj62fDxq6DygUog+W8rK"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:u+Jekx48rmgjBW4MkZoOeQEeJqI=
View all headers

B. Pym wrote:

> B. Pym wrote:
>
> > 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)
> >
>
>
> (define (collect-till pred gen key)
> (do ((x (gen) (gen))
> (res '() (cons x res)))
> ((pred x) (reverse res))))
>
> (with-input-from-file "output.dat"
> (lambda _
> (collect-till eof-object? read +)))

(with-input-from-file "output.dat"
(lambda _ (collect-while + read)))

Given:

(define (collect-while pred gen . opt-key)
(let ((key (if (pair? opt-key) (car opt-key) values)))
(do ((x (gen) (gen))
(res '() (cons (key x) res)))
((or (eof-object? x) (not (pred x))) (reverse res)))))

1

rocksolid light 0.9.8
clearnet tor