我已经使用Racket (以前的PLT Scheme)构建了一个相当复杂的应用程序,并希望添加一个REPL用于调试目的。我尝试让它可以通过TCP流访问:
(define repl-server
(thread (lambda ()
(let ((listener (tcp-listen 8082 5 #t)))
(do () (#f)
(let-values (((in out) (tcp-accept listener)))
(thread (lambda ()
(let ((port-string (get-port-string in)))
(Try "debug-repl" #f
(begin
(file-stream-buffer-mode out 'line)
(display-and-log "Password: " out)
(flush-output out)
(when (string=? (read-line in) "whatever")
(log "Connect to REPL: " port-string))
(current-input-port in)
(current-output-port out)
(current-error-port out)
(read-eval-print-loop))
(close-input-port in)
(close-output-port out))))))))))))(Try name result-if-exception form)是一个提供基本异常处理的宏(LOG...)and (display-and-log...)听起来像什么就做什么。
现在,如果我访问REPL,我甚至不能计算常量,因为我一直得到错误compile: unbound identifier (and no #%app syntax transformer is bound) at: #%top-interaction。我怎样才能让这个REPL工作呢?在启动REPL服务器之前,如何访问values defined?
发布于 2011-05-10 15:20:31
您使用的是read-eval-print-loop,它本质上与使用eval相同,因此会遇到类似的问题。有关详细说明,请参阅relevant Guide section。最好是完整地阅读它,但是您要寻找的答案要么是“名称空间”部分所描述的,要么是“名称空间和模块”部分所描述的--第一个是如果您想要一个顶层的名称空间,第二个是如果您想要一个与代码出现在其中的实际文件相对应的名称空间。(第一种方式通常更好--例如,如果您使用第二种方式,那么REPL用户就可以使用repl-server本身,这使得它成为一个有问题的特性……)
下面是它的样子:
...
(thread (lambda ()
(parameterize ([current-namespace (make-base-namespace)])
...same code...)))
...对于第二个,定义一个锚点并使用namespace-anchor->namespace,如该页面上的最后一个示例所示。
[顺便说一句,也可以看看run-server这个东西,它有点老了,但仍然有用。]
https://stackoverflow.com/questions/5946380
复制相似问题