[gambit-list] Transcript

TJ tjay.dreaming at gmail.com
Mon Jan 29 02:22:23 EST 2007


On 1/29/07, Marc Feeley <feeley at iro.umontreal.ca> wrote:
> > ...
>
> For completeness, could you send the correct code?
>
> Marc

Sure thing.

The flow diagram I sent previously was wrong. The "input-splitter"
procedure should send input from stdin to "repl-input-port" and
"transcript_port", not to "repl-input-port" and "output-splitter-port"

;========================================== Start

; Works fine as a standalone executable. Just tried it from the Gambit REPL
; and it doesn't seem to work there.

(define transcript-port (open-output-file (list path: "transcript-test-output"
                                                create: 'maybe
                                                buffering: #f
                                                append: #f)))

(define (my-repl)
  (define stdout (current-output-port)) ; just take the current input and
  (define stdin (current-input-port))   ; output ports.
  (define repl-input-port (open-string '(buffering: #f)))
  (define output-splitter-port (open-string '(buffering: #f)))

  (define (input-splitter)
    ; Sends stdin to the repl and the output splitter.
    (define (loop s)
      (display s repl-input-port)
      (newline repl-input-port)
      (force-output repl-input-port)
      (display s transcript-port)
      (newline transcript-port)
      (force-output transcript-port)
      (loop (read-line stdin)))
    (loop (read-line stdin)))

  (define (output-splitter)
    ; Sends output to the transcript and stdout.
    (define (loop s)
      ; Print semicolon so results show up as comments and I can (load ...)
      ; the transcript file directly.
      (display "; " transcript-port)
      (display s transcript-port)
      (newline transcript-port)
      (force-output transcript-port)
      (display "; " stdout)
      (display s stdout)
      (newline stdout)
      (force-output stdout)
      (loop (read-line output-splitter-port)))
    (loop (read-line output-splitter-port)))

  ; Start splitter procs.
  (thread-start!
    (make-thread input-splitter 'programmer-interface-input-splitter))
  (thread-start!
    (make-thread output-splitter 'programmer-interface-output-splitter))

  ; Start real repl.
  (set! ##stdio/console-repl-channel
        (##make-repl-channel-ports repl-input-port
                                   output-splitter-port))
  (##repl)

  (close-port repl-input-port)
  (close-port output-splitter-port))

(my-repl)

;============================================ End

Cheers,

TJ



More information about the Gambit-list mailing list