PasteRack.org
Paste # 630
2013-11-12 23:53:17

Forked from paste # 8580.

Fork as a new paste.

Paste viewed 689 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.       (sleep 1)
  15.       tempin))))
  16.  
  17. (define (foo)
  18.   (parameterize
  19.       ([current-input-port (open-input-string (format "hello~nworld~n"))])
  20.     (copy-port
  21.      (make-file-stream-input-port (current-input-port))
  22.      (current-output-port))))

=>