[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

close on synonym streams, etc

    Date: 18 Aug 86 20:25:45 EDT
    From: Charles Hedrick <HEDRICK@RED.RUTGERS.EDU>

    ... I could conceive of implementations where buffering is done 
    in each stream.  In that case, it might be a good idea to close 
    a synonym or broadcast stream, in order to make sure that any 
    buffered characters are taken care of and any cleanup is done. 

It looks to me like this issue is adequately addressed by the presence
of FINISH-OUTPUT and FORCE-OUTPUT. Perhaps the documentation could be
clearer on that point.

    ... If you intend to outlaw close on one of these composite streams,
    then you should mention this fact clearly where synonym and broadcast
    streams are defined, and note that this means that they must be
    implemented in such a way that a close is not required when you are
    finished using them.

Indeed, the documentation should be clear about these points.

It seems to me, however, that the only point to CLOSE is that it 
allows the freeing of things like operating system "channels" 
which are often critical resources. In that respect, it's like 
a fast GC. If they weren't critical resources, I assume we'd 
just drop pointers to streams and let the GC take care of 
straightening out the resources in its own sweet time. 

Since echo and broadcast streams are presumably just lisp objects 
which have slots containing other streams, I see no reason to worry
about fast GC of them. Statistically, I bet their components will
tend to (not really coincidentally) get closed anyway by other
mechanisms. eg, consider:


The file stream will get closed fine by the WITH-OPEN-FILE. The echo
stream (holding the closed file stream) will eventually get cleaned 
up by the GC. That should be fine. No one's going to miss the couple
of conses which is presumably the only resource being used in the

It's true that there may be certain situations where you might think
ECHO-STREAM-OUTPUT-STREAM operations in order to clean up the loose 
ends. Eg, you might have done:


and maybe you later want to close the encapsulated real stream, but my
feeling is that it was so easy for you to have done:


that there just isn't any way to claim that the language didn't let 
you do what you wanted to do. In fact, if someone else wrote the module 
that gave you the pointer to the echo stream and that person wouldn't 
give you the encapsulated stream, maybe it was for a reason. If so, 
you're asking a lot by claiming it should be ok to be closing that 
encapsulated stream...