Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"

5 views
Skip to first unread message

Richard James Panturis Giuly

unread,
Aug 21, 2000, 3:00:00 AM8/21/00
to
In ACL on Linux, I use run-shell-command to start a process that
generates output to stdout. I can read from the stream that
run-shell-command returns with read-char but I need to be reading
bytes, not characters. When I try to use read-byte it says

Error: No methods applicable for generic function
#<STANDARD-GENERIC-FUNCTION STREAM-READ-BYTE> with args
(#<BIDIRECTIONAL-TERMINAL-STREAM fd 16/15 @ #x20256dca>)
of classes
(BIDIRECTIONAL-TERMINAL-STREAM)

how can I read bytes instead efficiently?

--
ricky
rgi...@surfsouth.com

Lieven Marchand

unread,
Aug 22, 2000, 3:00:00 AM8/22/00
to

On Unix, character streams and byte streams are fairly
interchangeable. Have you measured READ-CHAR is actually slower than
READ-BYTE?

If this is really the case, you could try doing a CHANGE-CLASS on your
stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can
create your own binary stream and give that as argument to the :output
key argument of RUN-SHELL-COMMAND.

--
Lieven Marchand <m...@bewoner.dma.be>
Lambda calculus - Call us a mad club

Erik Naggum

unread,
Aug 22, 2000, 3:00:00 AM8/22/00
to
* Richard James Panturis Giuly <n...@spam.com>

| how can I read bytes instead efficiently?

Which inefficient solutions have you tried so far? (Since you use
one of those extremely annoying invalid return addresses, I'm not
inclined to provide you with the solution I used ere the dawn of
bivalentน streams in Allegro CL.)

#:Erik
-------
น "multivalent" in recent terminology change, but it sounds silly
--
If this is not what you expected, please alter your expectations.

Richard James Panturis Giuly

unread,
Aug 22, 2000, 3:00:00 AM8/22/00
to
When I convert the input stream to an INPUT-BINARY-SOCKET-STREAM,
the read-byte function works but still gives characters. I need
integers (or numbers of some kind) rather than characters.

I don't know how to create a binary stream, could you fill me in?
(All I found were functions to make streams from existing
streams.)

If you know how I can convert a character to an integer that
would be fine too, I just thought converting every byte might be
inefficient.


>
> On Unix, character streams and byte streams are fairly
> interchangeable. Have you measured READ-CHAR is actually slower than
> READ-BYTE?
> If this is really the case, you could try doing a CHANGE-CLASS on your
> stream to BIDIRECTIONAL-BINARY-SOCKET-STREAM. Alternatively, you can
> create your own binary stream and give that as argument to the :output
> key argument of RUN-SHELL-COMMAND.

--
ricky
rgi...@surfsouth.com

Tim Bradshaw

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
* Richard James Panturis Giuly wrote:

> If you know how I can convert a character to an integer that
> would be fine too, I just thought converting every byte might be
> inefficient.

CHAR-CODE gets the code of a character. It's unlikely to be
inefficient compared to doing I/O.

--tim

Erik Naggum

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
* Richard James Panturis Giuly <n...@spam.com>

| If you know how I can convert a character to an integer that would
| be fine too, I just thought converting every byte might be
| inefficient.

The function char-code returns the integer code of the character.
It's essential a type-changing function, as both characters and
integers are immediate values, and at least in Allegro CL is a
simple bit-shift operation if you declare the character's type.

#:Erik

Lieven Marchand

unread,
Aug 23, 2000, 3:00:00 AM8/23/00
to
Richard James Panturis Giuly <n...@spam.com> writes:

> I don't know how to create a binary stream, could you fill me in?
> (All I found were functions to make streams from existing
> streams.)

I still think you're optimizing something that will be lost in the
fringe, but one way to do it is like this:

(defun test-function ()
(let ((stream (open "/tmp/foo"
:direction :io
:if-exists :supersede
:element-type 'unsigned-byte))
(output-buffer (make-array 1024 :element-type 'unsigned-byte)))
(run-shell-command "ls" :output stream)
(file-position stream 0)
(read-sequence output-buffer stream)
(close stream)
output-buffer))

Add all apropriate declarations and this could be quite fast.

USER(35): (setf *foo* (test-function))
#(35 46 110 101 119 115 114 99 45 108 ...)

USER(39): (loop for c across *foo*
collect (code-char c))
(#\# #\. #\n #\e #\w #\s #\r #\c #\- #\l ...)

Erik Naggum

unread,
Aug 25, 2000, 3:00:00 AM8/25/00
to
* Lieven Marchand <m...@bewoner.dma.be>

| USER(39): (loop for c across *foo*
| collect (code-char c))
| (#\# #\. #\n #\e #\w #\s #\r #\c #\- #\l ...)

(map 'list #'char-code <sequence>)

0 new messages