Re: When does ADJUST-ARRAY cons?

Liste des GroupesRevenir à cl scheme 
Sujet : Re: When does ADJUST-ARRAY cons?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 11. Sep 2024, 11:16:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbrn4q$3h62b$1@dont-email.me>
References : 1
User-Agent : XanaNews/1.18.1.6
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)."

Date Sujet#  Auteur
11 Sep 24 * Re: When does ADJUST-ARRAY cons?3B. Pym
11 Sep 24 +- Re: When does ADJUST-ARRAY cons?1Kaz Kylheku
11 Sep 24 `- Re: When does ADJUST-ARRAY cons?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal