The way I look at it, read is a very generic function whose semantics support a
wide array of use cases. Using partially_initialized_array reflects the full
generality of those semantics. Surely no one would dispute that if I want the
behavior of any old bytes remaining initialized, that behavior is indeed
guaranteed by the standard and all implementations?
One particular possible use case that comes to mind: Perhaps I store some
default value in my buffer, and then allow it to be overridden by something I
read from a file descriptor. Then if read returns 0 or -1, my buffer is still
ready to go to use however I wanted.
~Shea> On Apr 16, 2015, at 10:51 AM, gmhwxi gmh...@gmail.com wrote:
Personally, I feel max(fill, res) in the following interface for read
is problematic:
If you call ‘read’, the buffer gets overwritten. Logically, there isn’t
obvious justification for combining old buffer content and new buffer
content in this way.
fn read { fd: nat } { buf: addr } { fill, total: nat | fill <= total }
( ev: !errno_v ( free ) >> neg1_errno ( res )
, fdprf: !readable_filedes ( fd )
, !partially_initialized_array_v ( byte, fill, total, buf ) >>
partially_initialized_array_v ( byte, max ( fill, res ), total, buf )
| fd: int ( fd )
, buf: ptr buf
, total: size_t total
): #[ res: int ] ssize_t ( res ) = “ext#”
On Thursday, April 16, 2015 at 7:52:50 AM UTC-4, Shea Levy wrote:
Hi all,
In version 1.1.0.0 of my file descriptor library, I introduced a view for
partially initialized arrays 1, which allows me to cleanly represent a
contiguous array that may have some elements initialized but may not have all
elements initialized. This is used in the type of the POSIX read function 2,
which may increase (but not decrease) the number of initialized values in the
array.
It seems like this is a generally useful concept applicable outside of this
library, so I was wondering: Would this be welcome in the prelude or in libats?
If so, where does it best fit?
Thanks,
Shea
–
You received this message because you are subscribed to the Google Groups “ats-lang-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/edd706ea-8cba-4b64-88d8-c39b23f41e83%40googlegroups.com.