[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read-all ?
From: |
Andy Wingo |
Subject: |
Re: read-all ? |
Date: |
Tue, 22 Jan 2013 12:04:51 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) |
On Tue 22 Jan 2013 11:01, address@hidden (Ludovic Courtès) writes:
>>> Are the names right?
>
> ‘read-all’ doesn’t convey the idea that it’s textual (unlike the R6RS
> names).
>
> Perhaps ‘port-contents-as-string’, or ‘read-all-string’, or...?
What about read-string with an optional #:count argument ?
>> + (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 ‘get-string-n!’.
It is exactly what %read-delimited does, though, and that's the most
efficient thing we have. read-string/partial! does something more
clever, but I don't understand it fully. I was thinking (ice-9 ports)
could be appropriate if we exposed port buffers to scheme, because that
way we could read characters in bulk. Dunno.
> Given that ‘string-set!’ is (unduly) costly, I wonder if consing all the
> chars and then calling ‘list->string’ wouldn’t be more efficient in time
> (it’d be less efficient in space.)
Probably not, I would say that the interface is more important than the
implementation.
So, proposal: read-all{,!} to read-string{,!} and add optional count
argument to read-string, and leave it in ice-9 rdelim. WDYT?
Andy
--
http://wingolog.org/