From: Pete K. <pet...@ka...> - 2004-06-20 03:00:45
|
Is there any reason why OUTPUT-STREAM-P is not specialized for a FUNDAMENTAL-INPUT-STREAM? And likewise, is there any reason why INPUT-STREAM-P is not specialized for a FUNDAMENTAL-OUTPUT-STREAM in gray-streams.lisp? In the current SBCL codebase, INPUT-STREAM-P is only specialized on a FUNDAMENTAL-INPUT-STREAM, while OUTPUT-STREAM-P is only specialized on a FUNDAMENTAL-OUTPUT-STREAM. As a result, if someone wants to subclass either of these streams (as they were designed to be), he/she must also implement an additional method which could just as well have been implemented by the superclass. I.e., if I subclass FUNDAMENTAL-INPUT-STREAM, I'm forced to implement a specialized OUTPUT-STREAM-P, which simply returns NIL. Could this not be specialized for the parent class? After reading the original Gray proposal, it seems his intent was that default implementations for OUTPUT-STREAM-P and INPUT-STREAM-P would be specialized for the FUNDAMENTAL-INPUT/OUTPUT-STREAMs, here is a quote from the original proposal: STREAMP object [Generic Function] INPUT-STREAM-P stream [Generic Function] OUTPUT-STREAM-P stream [Generic Function] These three existing predicates may optionally be implemented as generic functions for implementations that want to permit users to define streams that are not STANDARD-OBJECTs. Normally, the default methods provided by classes FUNDAMENTAL-INPUT-STREAM and FUNDAMENTAL-OUTPUT-STREAM are sufficient. And then later in the proposal are his implementations for both INPUT-STREAM-P and OUTPUT-STREAM-P. Notice that both have been specialized for both FUNDAMENTAL-INPUT-STREAM as well as FUNDAMENTAL-OUTPUT-STREAM: (defmethod INPUT-STREAM-P ((stream fundamental-input-stream)) t) (defmethod INPUT-STREAM-P ((stream fundamental-output-stream)) ;; allow the two classes to be mixed in either order (typep stream 'fundamental-input-stream)) (defmethod OUTPUT-STREAM-P ((stream fundamental-output-stream)) t) (defmethod OUTPUT-STREAM-P ((stream fundamental-input-stream)) (typep stream 'fundamental-output-stream)) SBCL only implements the two of the above methods which forces a user to implement the unimplemented methods themselves. Here is the corresponding SBCL code: (defmethod INPUT-STREAM-P ((stream fundamental-input-stream)) t) (defmethod OUTPUT-STREAM-P ((stream fundamental-output-stream)) t) Is there any reason why SBCL cannot be modified to provide the default implementations for the two missing methods? I've searched the web for any other info on why these two methods might not have been added and was not able to find anything of significance. I have included a patch that adds the methods as well as two additional test cases to verify the functionality. Thanks, Pete |