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, 05:54:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbr4aa$3e40s$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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


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