From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: read-all ? Date: Tue, 22 Jan 2013 11:01:35 +0100 Message-ID: <8738xtk03k.fsf@gnu.org> References: <87hammwbj0.fsf@pobox.com> <87y5fyt7tn.fsf@gnu.org> <877gn5zih2.fsf@pobox.com> <87k3r5y28j.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1358848905 5341 80.91.229.3 (22 Jan 2013 10:01:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Jan 2013 10:01:45 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Jan 22 11:02:03 2013 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Txag7-0000VS-MO for guile-devel@m.gmane.org; Tue, 22 Jan 2013 11:02:03 +0100 Original-Received: from localhost ([::1]:56337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txafq-0006FO-Ko for guile-devel@m.gmane.org; Tue, 22 Jan 2013 05:01:46 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:34910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txafm-0006FH-OQ for guile-devel@gnu.org; Tue, 22 Jan 2013 05:01:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Txafh-00074Q-SP for guile-devel@gnu.org; Tue, 22 Jan 2013 05:01:42 -0500 Original-Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]:26292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Txafh-00074H-M2 for guile-devel@gnu.org; Tue, 22 Jan 2013 05:01:37 -0500 X-IronPort-AV: E=Sophos;i="4.84,513,1355094000"; d="scan'208";a="169294508" Original-Received: from unknown (HELO pluto) ([193.50.110.227]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 22 Jan 2013 11:01:36 +0100 X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 3 =?utf-8?Q?Pluvi=C3=B4se?= an 221 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <87k3r5y28j.fsf@pobox.com> (Andy Wingo's message of "Tue, 22 Jan 2013 10:51:40 +0100") User-Agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.105 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:15527 Archived-At: Hi! Andy Wingo skribis: > On Tue 22 Jan 2013 10:15, Andy Wingo writes: [...] >> Patch attached. I didn't update the docs because it wasn't clear to me >> that (ice-9 rdelim) is actually the right place to put it. >> >> What do you think? Should we perhaps put it in a new (ice-9 ports)? I would avoid adding a new module, unless there are other things to put in there. >> Are the names right? =E2=80=98read-all=E2=80=99 doesn=E2=80=99t convey the idea that it=E2=80=99= s textual (unlike the R6RS names). Perhaps =E2=80=98port-contents-as-string=E2=80=99, or =E2=80=98read-all-str= ing=E2=80=99, or...? > +(define* (read-all! buf #:optional > + (port (current-input-port)) > + (start 0) (end (string-length buf))) > + "Read all of the characters out of PORT and write them to BUF. > +Returns the number of characters read. > + > +This function only reads out characters from PORT if it will be able to > +write them to BUF. That is to say, if BUF is smaller than the number of > +available characters, then BUF will be filled, and characters will be > +left in the port." > + (check-arg buf (string? buf) "not a string") > + (check-arg start (index? start) "bad index") > + (check-arg end (index? end) "bad index") > + (check-arg start (<=3D start end) "start beyond end") > + (check-arg end (<=3D end (string-length buf)) "end beyond string lengt= h") > + (let lp ((n start)) > + (if (< n end) > + (let ((c (read-char port))) > + (if (eof-object? c) > + (- n start) > + (begin > + (string-set! buf n c) > + (lp (1+ n))))) > + (- n start)))) As you note, this is fairly inefficient, like =E2=80=98get-string-n!=E2=80= =99. Given that =E2=80=98string-set!=E2=80=99 is (unduly) costly, I wonder if co= nsing all the chars and then calling =E2=80=98list->string=E2=80=99 wouldn=E2=80=99t be m= ore efficient in time (it=E2=80=99d be less efficient in space.) Thanks! Ludo=E2=80=99.