[gambit-list] repl-output-port as dynamic variable for SLIME?
James Long
longster at gmail.com
Mon Jan 18 12:34:06 EST 2010
Marc and others,
I'm having a bit of trouble integrating proper output handling in
swank-gambit. Gambit's special REPL ports (repl-input-port and
repl-output-port) conflicts with what we want to do since SLIME is handling
the REPL now and makes things difficult.
For example, when I eval code in swank-gambit, it does something like this:
(let ((result #f))
(let ((output (with-output-to-string ""
(set! result (eval form)))))
...))
Yes, it's a bit awkward because I want both the output and the result for
the evaluation. So we capture any output from the evaluation in the
`output` variable so that we can send it to SLIME.
The problem is that `pp` by default prints to `repl-output-port`.
`repl-output-port` is not a dynamic variable; it is a hardcoded special
port. So I cannot in any way capture its output when I'm evaluating forms,
unless users specifically pass `current-output-port` to `pp` as the port,
which is confusing.
Now, I have successfully redirected the repl ports to the current ports with
the following code:
(define (thread-make-swank-repl-channel thread)
(##make-repl-channel-ports (current-input-port)
(current-output-port)))
(set! ##thread-make-repl-channel
thread-make-swank-repl-channel)
This lets me capture anything to `repl-output-port` because it sends it to
`current-output-port`. However, now we have a problem. Any thread
*outside* of SLIME evaluations (say, any part of the application we are
debugging) needs to have different behavior. If a slime client is
connected, I think all output from an application should be redirected to
SLIME in some fashion, and this could be done by overriding
##thread-make-repl-channel.
The solution is to set ##thread-make-repl-channel to create ports which
forward output to a SLIME connect if connected. But when I'm evaluating
code sent from SLIME, I want to capture the output sent to
`repl-output-port`, so I want to treat it as a dynamic variable like so:
(let ((result #f))
(let ((output (with-output-to-string ""
(parameterize ((repl-output-port (current-output-port)))
(set! result (eval form))))))
...))
Either we need to rethink that fact that `pp` sends output to
`repl-output-port` by default, treat `repl-output-port` as a dynamic
variable, or do something to make all this clearer. It's very confusing.
- James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20100118/b747ecf7/attachment.htm>
More information about the Gambit-list
mailing list