Waiting on custom ports / CL Gray Streams
Lassi Kortela 04 Mar 2020 15:41 UTC
> Third option - perhaps the simplest - just declare the result of
> {u8,char}-ready? on custom ports to be unspecified. This effectively
> makes them portably useless w.r.t. custom ports, but doesn't prohibit an
> implementation from doing better.
Arthur said MIT Scheme allows adding arbitrary user-defined methods to a
port. A ready? procedure could be one of those. But it feels like ready?
for custom ports is a much more complex complex abstraction than the
already-quite-complex situation with OS file ports. Has anyone in the
Lisp/Scheme community explored the implications?
FWIW, here's the popular "Gray Streams" extension for Common Lisp:
<http://www.nhplace.com/kent/CL/Issues/stream-definition-by-user.html>.
STREAM-READ-CHAR-NO-HANG stream [Generic Function]
This is used to implement READ-CHAR-NO-HANG. It returns either a
character, or NIL if no input is currently available, or :EOF if
end-of-file is reached. The default method provided by
FUNDAMENTAL-CHARACTER-INPUT-STREAM simply calls STREAM-READ-CHAR;
this is sufficient for file streams, but interactive streams
should define their own method.
STREAM-PEEK-CHAR stream [Generic Function]
Used to implement PEEK-CHAR; this corresponds to peek-type of NIL.
It returns either a character or :EOF. The default method calls
STREAM-READ-CHAR and STREAM-UNREAD-CHAR.
STREAM-LISTEN stream [Generic Function]
Used by LISTEN. Returns true or false. The default method uses
STREAM-READ-CHAR-NO-HANG and STREAM-UNREAD-CHAR. Most streams
should define their own method since it will usually be trivial
and will always be more efficient than the default method.