Deutsch English Français Italiano |
<vbrn4q$3h62b$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" <Nobody447095@here-nor-there.org> 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= Bytes: 2156 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)."