[plt-scheme] i/o streams

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jul 15 18:29:53 EDT 2004

At Wed, 14 Jul 2004 17:38:41 -0400, "Mike T. Machenry" wrote:
> Does anyone know how I can make an editor-stream-out%, write out to it, and
> then read back from it by making it into an editor-stream-in%? It seems like
> this would be a more convinient way to hand the copy method of snip% by
> reusing the write method.

There's a bug in editor-stream-out-string-base%, which might have made
things difficult. But here's an example that works around the bug.


 (define orig-snip (make-object string-snip% "hello"))

 (define out (make-object editor-stream-out-string-base%))
 (define out-stream (make-object editor-stream-out% out))

 (send orig-snip write out-stream)
 (send out-stream put 0) ; <--------- works around a bug that makes
                         ;            get-string's result short by 1 char

 (define in (make-object editor-stream-in-string-base% (send out get-string)))
 (define in-stream (make-object editor-stream-in% in))

 (define new-snip
   (send (send (get-the-snip-class-list) 
               find 
               (send (send (new string-snip%) get-snipclass) get-classname))
	 read in-stream))


Matthew



Posted on the users mailing list.