fix typo, more explanations, better IO sample code
svn: r11414
This commit is contained in:
parent
a56b3bff61
commit
524cf0414d
|
@ -197,12 +197,36 @@ example, here is a quick implementation of a networked REPL:
|
|||
(parameterize ([current-input-port i]
|
||||
[current-output-port o]
|
||||
[current-error-port o]
|
||||
[current-eval a])
|
||||
[current-eval e])
|
||||
(read-eval-print-loop)
|
||||
(fprintf o "\nBye...\n")
|
||||
(close-output-port o)))
|
||||
]
|
||||
|
||||
Note that in this code it is only the REPL interactions that are going
|
||||
over the network connection; using I/O operations inside the REPL will
|
||||
still use the usual sandbox parameters (defaulting to no I/O). In
|
||||
addition, the code works only from an existing toplevel REPL --- when
|
||||
run from a module, the input syntax values will not have a correct
|
||||
context. Here is a variation that uses the networked ports for user
|
||||
I/O, and works when used from a module (by using a new namespace):
|
||||
|
||||
@schemeblock[
|
||||
(let-values ([(i o) (tcp-accept (tcp-listen 9999))])
|
||||
(parameterize ([current-input-port i]
|
||||
[current-output-port o]
|
||||
[current-error-port o]
|
||||
[sandbox-input i]
|
||||
[sandbox-output o]
|
||||
[sandbox-error-output o])
|
||||
(parameterize ([current-namespace (make-base-namespace)]
|
||||
[current-eval
|
||||
(make-module-evaluator '(module m scheme/base))])
|
||||
(read-eval-print-loop))
|
||||
(fprintf o "\nBye...\n")
|
||||
(close-output-port o)))
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
@; ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user