Hello Richard,
I'll focus my answer to the problem of reading/writing binary data. Using plain text to transfer information between programs always strike me as utterly inefficient anyway (even if it is often greatly appreciated in practice), and reading/writing from a user terminal doesn't need to be efficient.
All other information sources (disk files, sockets, unix pipes...) can typically be accessed a block at a time. Actually, in Unix, the native OS call is the block-oriented 'read' and 'write' for all types of file descriptors, even for conceptually character-oriented pipes.
On Wed, May 14, 2003 at 01:33:05PM +0200, Richard A. O'Keefe wrote:
For the sake of argument, let's suppose that there was a built-in predicate
read_block(Stream, Block, Length)with the same argument order as POSIX.1's read(2).
OK, what are the type and mode of Block?
As you point out, it has to be -, and the only reasonable data structure it can return is some kind of native packed string (like in SWI Prolog). But the overhead of having to allocate that memory is minimal. It is an amortized constant. Actually reading data into that buffer is a single system call. There is no need for any loop in your program, the OS kernel handles all details. You just cannot make it more efficient on a Unix architecture (disregarding mmap(), which I concede has strong limitations).
On Unix applications, implementing block-reading in term of character-reading is an abstraction inversion (http://cliki.tunes.org/Abstraction%20Inversion) because the kernel natively provides block-reading.
To wrap up, there is a logic programming language with Prolog-like syntax in which it *is* possible to do byte-block-at-a-time I/O without breaking the language's semantics, and that is Mercury.
You are too concerned about the allocation cost. A lot of high-level languages more dynamic than Mercury have immutable string-like buffers and very successfully return them as a result of a block-reading operation (http://www.python.org).
Armin Rigo ============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------