Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #99: SIMM crosstalk.


comp / comp.lang.lisp / Re: When does ADJUST-ARRAY cons?

SubjectAuthor
* Re: When does ADJUST-ARRAY cons?B. Pym
+- Re: When does ADJUST-ARRAY cons?Kaz Kylheku
`- Re: When does ADJUST-ARRAY cons?B. Pym

1
Subject: Re: When does ADJUST-ARRAY cons?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Wed, 11 Sep 2024 03:54 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,comp.lang.scheme
Subject: Re: When does ADJUST-ARRAY cons?
Date: Wed, 11 Sep 2024 03:54:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <vbr4aa$3e40s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 11 Sep 2024 05:54:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f75513ee18371f2bf12b5336f2430a5a";
logging-data="3608604"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qP4RbsOTeMeJAmuaIVZXo"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:eOBNNzjLtp3212hRwWsjnK1UFq8=
View all headers

Edi Weitz wrote:

> (defun foo ()
> (with-open-file (strm "/tmp/test.big")
> (loop as line = (read-line strm nil nil)
> while line
> summing (length line))))

Bad. Very bad. Fails to remove any carriage return
at the end of the line. Consequently, the sum
may be incorrect.

Instead of CL, let's use a Lispy language.

Sum the lengths of all of the lines in a text file.
The length of a line is measured after removing the
end-of-line characters at the end.

Gauche Scheme

(use gauche.generator)

(define (foo f)
(generator-fold
+ 0
(gmap string-length (file->generator f read-line))))

(foo "output.dat")
===>
119

Subject: Re: When does ADJUST-ARRAY cons?
From: Kaz Kylheku
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Wed, 11 Sep 2024 04:29 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,comp.lang.scheme
Subject: Re: When does ADJUST-ARRAY cons?
Date: Wed, 11 Sep 2024 04:29:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <20240910212840.827@kylheku.com>
References: <vbr4aa$3e40s$1@dont-email.me>
Injection-Date: Wed, 11 Sep 2024 06:29:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5ab64ce9d15f322c7a71bbb7db598b81";
logging-data="3618988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z1/CLRvqPnLolUMOxblR3TJJOp0AsV+c="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:5clYbOrb9TTO9fcuDFfFLD5apUE=
View all headers

On 2024-09-11, B. Pym <Nobody447095@here-nor-there.org> wrote:
> Gauche Scheme
>
> (use gauche.generator)
>
> (define (foo f)
> (generator-fold
> + 0
> (gmap string-length (file->generator f read-line))))
>
> (foo "output.dat")
> ===>
> 119

Yagoddabekidding!

1> (lflow "/etc/hosts"
file-get-lines
(sum len))
213

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

Subject: Re: When does ADJUST-ARRAY cons?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Wed, 11 Sep 2024 09:16 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,comp.lang.scheme
Subject: Re: When does ADJUST-ARRAY cons?
Date: Wed, 11 Sep 2024 09:16:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <vbrn4q$3h62b$1@dont-email.me>
References: <vbr4aa$3e40s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Wed, 11 Sep 2024 11:16:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e9067e4b4075622bfe91bd4278672e61";
logging-data="3709003"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/KlwlO//MQfsdTf7y14tT9"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:evlzktWegNiDtaXZpRS4Ai9zHOs=
View all headers

B. Pym wrote:

> Edi Weitz wrote:
>
> > (defun foo ()
> > (with-open-file (strm "/tmp/test.big")
> > (loop as line = (read-line strm nil nil)
> > while line
> > summing (length line))))
>
> Bad. Very bad. Fails to remove any carriage return
> at the end of the line. Consequently, the sum
> may be incorrect.
>
>
> Instead of CL, let's use a Lispy language.
>
> Sum the lengths of all of the lines in a text file.
> The length of a line is measured after removing the
> end-of-line characters at the end.
>
> Gauche Scheme
>
> (use gauche.generator)
>
> (define (foo f)
> (generator-fold
> + 0
> (gmap string-length (file->generator f read-line))))
>
> (foo "output.dat")
> ===>
> 119

The "hyperspec" says:

"The primary value, line, is the line that is read, represented
as a string (without the trailing newline, if any)."

No mention is made of the carriage-return. My testing with
SBCL proves that the CR isn't removed.

Gauche Scheme:

"Reads one line (a sequence of characters terminated by
newline or EOF) and returns a string. The terminating newline
is not included. This function recognizes popular line
terminators (LF only, CRLF, and CR only)."

1

rocksolid light 0.9.8
clearnet tor