[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: binary-port?
From: |
Marco Maggi |
Subject: |
Re: binary-port? |
Date: |
Sun, 24 Apr 2011 08:39:28 +0200 |
Ludovic Courtès wrote:
>>> However, I’m wondering whether we should not just
>>> squarely do away with the binary/textual distinction
How would you handle port position? From R6RS[1]:
(port-has-port-position? port) procedure
(port-position port) procedure
The port-has-port-position? procedure returns #t if the
port supports the port-position operation, and #f
otherwise.
For a binary port, the port-position procedure returns
the index of the position at which the next byte would
be read from or written to the port as an exact
non-negative integer object. For a textual port,
port-position returns a value of some
implementation-dependent type representing the port’s
position; this value may be useful only as the pos
argument to set-port-position!, if the latter is
supported on the port (see below).
If the port does not support the operation,
port-position raises an exception with condition type
&assertion.
Note: For a textual port, the port position may or may
not be an integer object. If it is an integer object,
the integer object does not necessarily correspond to
a byte or character position.
(port-has-set-port-position!? port) procedure
(set-port-position! port pos) procedure
If port is a binary port, pos should be a non-negative
exact integer object. If port is a textual port, pos
should be the return value of a call to port-position on
port.
I do not know how current Guile handles ports; if
internally you mark a binary port to handle the position
char-wise (so that it is meant to be a textual port) and
BINARY-PORT? returns #t: what does GET-U8 do?
> Do you know what Industria, Nausicaa, & co. do?
Nausicaa uses BINARY-PORT? and TEXTUAL-PORT? only when
establishing the conventional class of a port value; as far
as I remember it does it in the same way GOOPS does to
dispatch multimethods.
IMHO this R6 statement:
(textual-port? port) procedure
(binary-port? port) procedure
The textual-port? procedure returns #t if port is
textual, and returns #f otherwise. The binary-port?
procedure returns #t if port is binary, and returns #f
otherwise.
should be enough to derive that:
(cond ((binary-port? p)
---)
((textual-port? p)
---))
and:
(cond ((textual-port? p)
---)
((binary-port? p)
---))
must be equivalent; if they are not, confusion arises
because of violation of the rule of least surprise.
[1] <http://www.r6rs.org/final/html/r6rs-lib/r6rs-lib-Z-H-9.html#node_sec_8.2.6>
--
Marco Maggi
- binary-port?, Ludovic Courtès, 2011/04/22
- Re: binary-port?, Andreas Rottmann, 2011/04/22
- Re: binary-port?, Ludovic Courtès, 2011/04/23
- Re: binary-port?, Andreas Rottmann, 2011/04/25
- Re: binary-port?, Ludovic Courtès, 2011/04/25
- Re: binary-port?, Andy Wingo, 2011/04/25
- Re: binary-port?, Andreas Rottmann, 2011/04/25
- Re: binary-port?, Ludovic Courtès, 2011/04/26