PasteRack.org
Paste # 8580
2013-11-12 15:40:33

Fork as a new paste.

Paste viewed 733 times.


Embed:

wrap input-port

  1. #lang racket
  2.  
  3. (define (make-file-stream-input-port port)
  4.   (cond
  5.    ((file-stream-port? port) port)
  6.    (else
  7.     (let* ([tempfile (make-temporary-file)]    ;[!HACK!] file's never deleted
  8.            [tempin (open-input-file tempfile)]
  9.            [tempout (open-output-file tempfile #:exists 'truncate)]
  10.            [pumpth (thread
  11.                     (thunk (begin
  12.                              (displayln "THREAD HERE:")
  13.                              (copy-port port tempout))))])
  14.       tempin))))
  15.  
  16. (define (foo)
  17.   (parameterize
  18.       ([current-input-port (open-input-string (format "hello~nworld~n"))])
  19.     (copy-port
  20.      (make-file-stream-input-port (current-input-port))
  21.      (current-output-port))))

=>