From: Richard James Panturis Giuly
Subject: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <39A1D958.14924444@spam.com>
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
	······@surfsouth.com

From: Lieven Marchand
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <m3vgwt5ikf.fsf@localhost.localdomain>
Richard James Panturis Giuly <··@spam.com> writes:

> 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?

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 <···@bewoner.dma.be>
Lambda calculus - Call us a mad club
From: Richard James Panturis Giuly
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <39A31D18.7024041C@spam.com>
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
	······@surfsouth.com
From: Tim Bradshaw
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <ey31yzg1d8b.fsf@cley.com>
* 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
From: Erik Naggum
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <3176015533325327@naggum.net>
* Richard James Panturis Giuly <··@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
-- 
  If this is not what you expected, please alter your expectations.
From: Lieven Marchand
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <m3zom3kilx.fsf@localhost.localdomain>
Richard James Panturis Giuly <··@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 ...)


-- 
Lieven Marchand <···@bewoner.dma.be>
Lambda calculus - Call us a mad club
From: Erik Naggum
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <3176196939254025@naggum.net>
* Lieven Marchand <···@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>)

#:Erik
-- 
  If this is not what you expected, please alter your expectations.
From: Erik Naggum
Subject: Re: q. on reading bytes from "BIDIRECTIONAL-TERMINAL-STREAM"
Date: 
Message-ID: <3175955972252449@naggum.net>
* Richard James Panturis Giuly <··@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.