I'm trying to write my own transcripting functions, but it's not working -.-
What I want is to have a custom repl "front-end" function that reads from stdin and passes it to the real REPL and also prints it to the stdout and to my transcript file. Also, the output from the real REPL will be printed on both the stdout and transcript files.
Here's a diagram to help illustrate what I'm thinking of (ascii art):
------- -------- ----------------- | Stdin | | Stdout | | transcript-port | ------- -------- ----------------- | /|\ /|\ | | | |/ \ / (proc input-splitter) ______________________/ | | | | | (proc output-splitter) | /|\ |_____________________________ | | | | |/ |/ | ----------------- ---------------------- | repl-input-port | | output-splitter-port | ----------------- ---------------------- \ /|\ \ | \ / | / |/ / (proc ##repl)
The problem is that (when compiled as a single program, which is what I want) the output seems to be buffered, even though I call force-output, and even if I open the port with buffering disabled.
When run from the REPL however, nothing whatsoever gets sent to the transcript file, however the fake repl displays to stdout just fine.
Here's a sample program:
;;========================================== Start (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)) (define output-splitter-port (open-string))
(define (input-splitter) ; Sends stdin to the repl and the output splitter. (define (loop s) (display "input-split") (display s repl-input-port) (force-output repl-input-port) (display s output-splitter-port) (force-output output-splitter-port) (loop (read-line stdin))) (loop (read-line stdin)))
(define (output-splitter) ; Sends output to the transcript and stdout. (define (loop s) (display "output-split") (display s transcript-port) (force-output transcript-port) (display s 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
Any idea what's wrong?
TJ