From: Christophe R. <cs...@ca...> - 2003-09-10 09:54:54
|
Nikodemus Siivola <tsi...@cc...> writes: > The attached string-*-stream patch provides for the following > behaviour and corresponding tests: > > MAKE-STRING-INPUT-STREAM > > * Observe FILE-POSITION :START and :END, and allow setting of > FILE-POSITION beyond the end of string, signalling END-OF-FILE only > on read. > > * If the input stream is resized or otherwise mutated the effects are > seen in the stream as well. I'm not sure I like this one. Most of the rest makes sense to me, but this I think is a bit weird. I'm at least slightly supported by WITH-INPUT-FROM-STRING on this one, which refers to the "Traversal Rules and Side Effects" bit. On the other hand, I can see the attraction of having mutations to the string's data take effect. > (defun make-string-input-stream (string &optional > (start 0) end) > #!+sb-doc > "Return an input stream which will supply the characters of STRING between > START and END in order." > - (declare (type string string) > + (declare (type (vector character *) string) Heh. Nice try, but now I can't do (make-string-input-stream (make-array 0 :element-type 'nil)) and I'm sure Paul Dietz will write a test for that eventually... > (type index start) > (type (or index null) end)) > - > - (internal-make-string-input-stream > - (coerce string 'simple-string) > - start > - (%check-vector-sequence-bounds string start end))) > + (let ((end (%check-vector-sequence-bounds string start end))) > + (internal-make-string-input-stream > + string > + start > + (if (or (adjustable-array-p string) (array-has-fill-pointer-p string)) > + (lambda () (min end (length string))) > + (constantly end))))) I have a feeling that this might hurt performance in a non-trivial way: not only are we calling arbitrary functions at each read, but each read will involve finding the underlying data. Perhaps what we want to do is something like (with-array-data ((string string) (start start) (end end)) (internal-make-input-stream string ; now the simple, underlying data, so mutations will be reflected start end ; no need for functions, since we disallow changing the string structure )) so that the stream string is now simple [ though not necessarily (simple-array character (*)); it could be (simple-array nil (*)); I think that's probably acceptable performancewise ] Does that make sense? Cheers, Christophe -- http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757 (set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b))) (defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge) |