From: Juergen Weiss
Subject: close of an arbitrary stream may close *terminal-io*
Date:
Message-ID: <weiss.766166896@casun>
Redirecting output to a file seems simple:
(with-open-stream (out (open "file" :direction output))
... )
But sometimes I would prefer output on the console:
(with-open-stream (out (if writeToFileIfTrue (open "file" :direction output)
*standard-output*))
... )
Problem:
When with-open-stream terminates, the system tries to
close *standard-output*.
First idea:
clone *standard-output* with make-synonym-stream.
Problem:
the closing of the synonym stream closes *standard-output* as well.
This is according to documentation (at least the old common lisp one)
and can be verified in the implementations of akcl and cmu lisp.
Ok, you can always use unwind-protect instead of with-open-stream.
But the above is only a simple example. My complaint is, that
it seems to be impossible to get a handle to a stream, which
can be manipulated (that is closed) without affecting the
original stream. In particular, *standard-input*, *standard-output*,
*error-output*,*trace-output*,*query-io* are all synonyms of
*terminal-io*. Closing any of those streams will result in
closing *termial-io*.
Writing a new close function, which avoids closing synonym
streams is impossibe in an implementation independent way,
since there is no predicate to test for a synonym stream.
Juergen Weiss
--
Juergen Weiss Gesellschaft fuer Mathematik und Datenverarbeitung (GMD)
Institut I1, Postfach 1316
53731 Sankt Augustin, Germany
·····@cartan.gmd.de Tel: 02241/14-2794
In article <···············@casun> ·····@casun.gmd.de (Juergen Weiss) writes:
Redirecting output to a file seems simple:
(with-open-stream (out (open "file" :direction output))
... )
But sometimes I would prefer output on the console:
(with-open-stream (out (if writeToFileIfTrue (open "file" :direction output)
*standard-output*))
... )
Problem:
When with-open-stream terminates, the system tries to
close *standard-output*.
Perhaps it would work to use:
(with-open-stream (out (make-broadcast-stream *standard-output*))
... )
Wayne Hyatt
AT&T (Bell Laboratories)
·····@ieain.att.com
In article <···············@casun> ·····@casun.gmd.de (Juergen Weiss) writes:
First idea:
clone *standard-output* with make-synonym-stream.
Problem:
the closing of the synonym stream closes *standard-output* as well.
This is according to documentation (at least the old common lisp one)
and can be verified in the implementations of akcl and cmu lisp.
CLtL2, p. 506, specifies: "Closing a composite stream has no effect on
its constituents; any constituents that are open remain open." On the
same page: "A composite stream is one that was returned by a call to
MAKE-SYNONYM-STREAM, MAKE-BROADCAST-STREAM, MAKE-CONCATENATED-STREAM,
MAKE-TWO-WAY-STREAM, or MAKE-ECHO-STREAM."
Writing a new close function, which avoids closing synonym
streams is impossibe in an implementation independent way,
since there is no predicate to test for a synonym stream.
P. 500 of CLtL2 specifies that "the result of MAKE-SYNONYM-STREAM is
always a stream of type SYNONYM-STREAM." Hence a suitable test is
(typep <stream> 'synonym-stream)
--
Lawrence G. Mayka
AT&T Bell Laboratories
···@ieain.att.com
Standard disclaimer.
WARNING: flame bait included!
:-)
In article <···············@casun> ·····@casun.gmd.de (Juergen Weiss) writes:
Newsgroups: comp.lang.lisp
From: ·····@casun.gmd.de (Juergen Weiss)
Keywords: with-open-stream, make-synonym-stream
Sender: ····@gmd.de (USENET News)
Nntp-Posting-Host: casun
Organization: GMD, Sankt Augustin, Germany
Date: Tue, 12 Apr 1994 16:08:16 GMT
Lines: 52
Redirecting output to a file seems simple:
(with-open-stream (out (open "file" :direction output))
... )
But sometimes I would prefer output on the console:
(with-open-stream (out (if writeToFileIfTrue (open "file" :direction output)
*standard-output*))
... )
Please, avoid ugly "C++" style in this group. Use:
(with-open-stream (out (if *write-to-file-p*
(open "file" :direction output)
*standard-output*))
... )
:-) :-)
--
Marco Antoniotti - Resistente Umano
-------------------------------------------------------------------------------
Robotics Lab | room: 1220 - tel. #: (212) 998 3370
Courant Institute NYU | e-mail: ·······@cs.nyu.edu
...e` la semplicita` che e` difficile a farsi.
...it is simplicity that is difficult to make.
Bertholdt Brecht
From: Barry Margolin
Subject: Re: close of an arbitrary stream may close *terminal-io*
Date:
Message-ID: <2oqhhgINNiu0@early-bird.think.com>
In article <···············@casun> ·····@casun.gmd.de (Juergen Weiss) writes:
>the closing of the synonym stream closes *standard-output* as well.
>This is according to documentation (at least the old common lisp one)
>and can be verified in the implementations of akcl and cmu lisp.
I'm surprised CMU CL still has this bug. CLtL2 clarifies that closing a
composite stream should not affect the streams it references.
--
Barry Margolin
System Manager, Thinking Machines Corp.
······@think.com {uunet,harvard}!think!barmar