ソースを参照

read-/write-sequence handling komplett umgestrickt

dlichteblau 20 年 前
コミット
098ea33eae
3 ファイル変更55 行追加25 行削除
  1. 7 4
      README
  2. 48 15
      mixin.lisp
  3. 0 6
      package.lisp

+ 7 - 4
README

@@ -14,7 +14,10 @@ How to use it
    implementation-specific package you would have to use otherwise to
    get at gray stream symbols.
 2. For STREAM-READ-SEQUENCE and STREAM-WRITE-SEQUENCE, notice that we
-   use two &OPTIONAL arguments.
-3. In order for (2) to work on Lispworks, CLISP, and OpenMCL, make sure to
-   subclass all your stream classes from TRIVIAL-GRAY-STREAM-MIXIN if you
-   intend to define methods on those two generic functions.
+   use two required arguments and allow additional keyword arguments.
+   So the lambda list when defining a method on either function should look
+   like this:
+     (stream sequence start end &key)
+3. In order for (2) to work on all Lisps, make sure to subclass all your
+   stream classes from TRIVIAL-GRAY-STREAM-MIXIN if you intend to define
+   methods on those two generic functions.

+ 48 - 15
mixin.lisp

@@ -2,37 +2,55 @@
 
 (defclass trivial-gray-stream-mixin () ())
 
-#+lispworks
+(defgeneric stream-read-sequence
+    (stream sequence start end &key &allow-other-keys))
+(defgeneric stream-write-sequence
+    (stream sequence start end &key &allow-other-keys))
+
+(defmethod stream-write-string
+    ((stream trivial-gray-stream-mixin) seq &optional start end)
+  (stream-write-sequence stream seq (or start 0) (or end (length seq))))
+
+#+allegro
+(progn
+  (defmethod excl:stream-read-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-read-sequence s seq (or start 0) (or end (length seq))))
+  (defmethod stream:stream-write-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-write-sequence s seq (or start 0) (or end (length seq)))))
+
+#+cmu
 (progn
-  (defgeneric stream-read-sequence (stream sequence &optional start end))
-  (defgeneric stream-write-sequence (stream sequence &optional start end))
+  (defmethod ext:stream-read-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-read-sequence s seq (or start 0) (or end (length seq))))
+  (defmethod ext:stream-write-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-write-sequence s seq (or start 0) (or end (length seq)))))
 
+#+lispworks
+(progn
   (defmethod stream:stream-read-sequence
       ((s trivial-gray-stream-mixin) seq start end)
-    (stream-read-sequence seq start end))
+    (stream-read-sequence s seq start end))
 
   (defmethod stream:stream-write-sequence
       ((s trivial-gray-stream-mixin) seq start end)
-    (stream-read-sequence seq start end)))
+    (stream-write-sequence s seq start end)))
 
 #+openmcl
 (progn
-  (defgeneric stream-read-sequence (stream sequence &optional start end))
-  (defgeneric stream-write-sequence (stream sequence &optional start end))
-
   (defmethod ccl:stream-read-vector
       ((s trivial-gray-stream-mixin) seq start end)
-    (stream-read-sequence seq start end))
+    (stream-read-sequence s seq start end))
 
   (defmethod ccl:stream-write-vector
       ((s trivial-gray-stream-mixin) seq start end)
-    (stream-write-sequence seq start end)))
+    (stream-write-sequence s seq start end)))
 
 #+clisp
 (progn
-  (defgeneric stream-read-sequence (stream sequence &optional start end))
-  (defgeneric stream-write-sequence (stream sequence &optional start end))
-
   (defmethod gray:stream-read-byte-sequence
       ((s trivial-gray-stream-mixin)
        seq
@@ -41,7 +59,7 @@
       (error "this stream does not support the NO-HANG argument"))
     (when interactive
       (error "this stream does not support the INTERACTIVE argument"))
-    (stream-read-sequence seq start end))
+    (stream-read-sequence s seq start end))
 
   (defmethod gray:stream-write-byte-sequence
       ((s trivial-gray-stream-mixin)
@@ -51,4 +69,19 @@
       (error "this stream does not support the NO-HANG argument"))
     (when interactive
       (error "this stream does not support the INTERACTIVE argument"))
-    (stream-write-sequence seq start end)))
+    (stream-write-sequence s seq start end)))
+
+#+sbcl
+(progn
+  (defmethod sb-gray:stream-read-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-read-sequence s seq (or start 0) (or end (length seq))))
+  (defmethod sb-gray:stream-write-sequence
+      ((s trivial-gray-stream-mixin) seq &optional start end)
+    (stream-write-sequence s seq (or start 0) (or end (length seq))))
+  ;; SBCL extension:
+  (defmethod sb-gray:stream-line-length ((stream trivial-gray-stream-mixin))
+    80)
+  ;; SBCL should provide this default method, but doesn't?
+  (defmethod stream-terpri ((stream trivial-gray-stream-mixin))
+    (write-char #\newline stream)))

+ 0 - 6
package.lisp

@@ -30,12 +30,6 @@
 			  #+openmcl :ccl
 			  #+lispworks :stream
 			  #-(or sbcl allegro cmu clisp openmcl lispworks) ...
-
-			  #-(or lispworks clisp openmcl)
-                          #:stream-read-sequence
-			  #-(or lispworks clisp openmcl)
-                          #:stream-write-sequence
-
 			  ,@common-symbols)
 	    (:export #:trivial-gray-stream-mixin
 		     #:stream-read-sequence