Hi!
I have a program that opens a serial stream as a split stream and both
writes and reads from this device. I would like to write a macro that
when called will result in all output that is sent to the serial
stream by the containing forms being dribbled to a file specified by
the user. I tried the following:
(defmacro with-file-as-well-as-dectalk ((&key (filename "temp")) &body body)
"Read into file instead of speaking. "
`(let (
(saved-stream dectalk:*stream*)
(file-stream
(open
(merge-pathnames
(user-homedir-pathname)
,filename )
:direction :io
:if-does-not-exist :create
))
)
(unwind-protect
(progn
(setf dectalk:*stream*
(make-broadcast-stream dectalk:*stream* file-stream))
,@body)
(setf dectalk:*stream*
saved-stream)
(close file-stream)
)
)
)
But the above does not work and I get an error as follows since the
broadcast stream will only allow output. How do I write the above so
that the file-stream gets connected only to the output side of the
split stream?
Is the above possible, and if so what is the clean way of doing it?
>>Error: Stream #<Stream BROADCAST-STREAM 15F7A26> is not open for input
READ-CHAR-NO-HANG:
Optional arg 0 (STREAM): #<Stream BROADCAST-STREAM 15F7A26>
Optional arg 1 (EOF-ERROR-P): T
Optional arg 2 (EOF-VALUE): NIL
Optional arg 3 (RECURSIVEP): NIL
:A 0: Abort to Lisp Top Level
->
--
T. V. Raman <·····@cs.cornell.edu>Tel: (607)255-9202 R 272-3649
Office: 4116 Upson Hall,
Department of Computer Science, Cornell University Ithaca NY 14853-6201
Res: 226 Bryant Avenue Ithaca NY 14850
In article <····················@cs.cornell.edu> ·····@cs.cornell.edu (T. V. Raman) writes:
>But the above does not work and I get an error as follows since the
>broadcast stream will only allow output. How do I write the above so
>that the file-stream gets connected only to the output side of the
>split stream?
Use MAKE-TWO-WAY-STREAM. The output side of the two-way stream should be
the broadcast stream that you constructed in your original code, and the
input side should be the stream that you're duplicating.
Also, you should use WITH-OPEN-STREAM to open and close these temporary
streams rather than your own UNWIND-PROTECT.
--
Barry Margolin
System Manager, Thinking Machines Corp.
······@think.com {uunet,harvard}!think!barmar