2

好的,我需要重写这个问题。

如果我走:

CL-USER> whatever

我在调试器框架中得到了这个:

The variable WHATEVER is unbound.
   [Condition of type UNBOUND-VARIABLE]

Restarts:
 0: [RETRY] Retry SLIME REPL evaluation request.
 1: [*ABORT] Return to SLIME's top level.
 2: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" RUNNING {C0C6CF9}>)
 ...

因此,我应该能够做到这一点:

(handler-case
    whatever
  (unbound-variable (e) (invoke-restart 'retry)))

然而它产生:

No restart RETRY is active.
   [Condition of type SB-INT:SIMPLE-CONTROL-ERROR]
...

我错过了什么?

ABORT 重试确实工作正常;感谢 hans 和 Svante 指出这一点。其他的 - 重试,终止线程等 - 都出错了。

我还尝试在调试器中按 e 并直接运行 INVOKE-RESTART。结果相同,但有一个例外:此答案中的低级示例就像我认为的那样工作:

Eval in frame (COMMON-LISP-USER)> (invoke-restart 'go-on)

无怨无悔地返回提示。仅当从重新启动菜单中手动选择时,高级示例才会正确重新启动。

4

4 回答 4

3

输出中 restart 1 前面的星号表示此重启将由 SLIME 的 [q]uit 命令调用。重新启动的名称是 'ABORT,因此要调用它,请使用以下命令:

(handler-case
    whatever
  (unbound-variable (e) (invoke-restart 'abort)))
于 2013-03-19T06:04:23.523 回答
2

retry只是再次尝试评估相同的变量。由于您没有绑定它,它仍然是未绑定的。你可能有更好的运气

(handler-case
    whatever
  (unbound-variable (e)
    (setq whatever 42)
    (invoke-restart 'swank::retry)))

应该返回 42。

于 2013-03-20T14:10:58.650 回答
2

如果你运行compute-restarts,你会看到重启retry实际上是swank包内部的:

(#<RESTART SWANK::RETRY {100462AE63}> #<RESTART ABORT {1003E4C2B3}>
 #<RESTART ABORT {1007138083}>)

如果您因此将其限定为swank::retry,您将获得预期的行为。

于 2013-03-20T14:41:19.140 回答
1

要查看所有重新启动并获取实际符号,请执行以下操作。请注意,调试器没有被调用,因此它的重新启动不可用。

CL-USER> (handler-case whatever
           (unbound-variable (c)
              (mapcar (lambda (r) (describe r) (terpri))
                      (compute-restarts c))
              (abort)))

我们得到:

#<RESTART SWANK::RETRY {10055BDB83}>                                                                                                                                                             
  [structure-object]                                                                                                                                                                             

Slots with :INSTANCE allocation:                                                                                                                                                                 
  NAME                  = SWANK::RETRY                                                                                                                                                           
  FUNCTION              = #<CLOSURE (LAMBDA (&REST SB-IMPL::TEMP)..                                                                                                                              
  REPORT-FUNCTION       = #<CLOSURE (LAMBDA (STREAM) :IN SWANK::CALL-WITH-RETRY-RESTART) {10055B..                                                                                               
  INTERACTIVE-FUNCTION  = NIL                                                                                                                                                                    
  TEST-FUNCTION         = #<FUNCTION (LAMBDA (COND)..                                                                                                                                            



#<RESTART ABORT {10055B9A83}>                                                                                                                                                                    
  [structure-object]                                                                                                                                                                             

Slots with :INSTANCE allocation:                                                                                                                                                                 
  NAME                  = ABORT                                                                                                                                                                  
  FUNCTION              = #<CLOSURE (LAMBDA (&REST SB-IMPL::TEMP) :IN SWANK::HANDLE-REQUESTS) {1..                                                                                               
  REPORT-FUNCTION       = #<FUNCTION (LAMBDA (STREAM) :IN SWANK::HANDLE-REQUESTS) {10041ECF6B}>                                                                                                  
  INTERACTIVE-FUNCTION  = NIL                                                                                                                                                                    
  TEST-FUNCTION         = #<FUNCTION (LAMBDA (COND)..                                                                                                                                            



#<RESTART SB-SYS:REMOVE-FD-HANDLER {10055B97D3}>                                                                                                                                                 
  [structure-object]                                                                                                                                                                             

Slots with :INSTANCE allocation:                                                                                                                                                                 
  NAME                  = SB-SYS:REMOVE-FD-HANDLER                                                                                                                                               
  FUNCTION              = #<CLOSURE (LAMBDA (&REST SB-IMPL::TEMP)..                                                                                                                              
  REPORT-FUNCTION       = #<CLOSURE (LAMBDA (STREAM) :IN SB-IMPL::SUB-SUB-SERVE-EVENT) {10055B97..                                                                                               
  INTERACTIVE-FUNCTION  = NIL                                                                                                                                                                    
  TEST-FUNCTION         = #<FUNCTION (LAMBDA (COND)..                                                                                                                                            




#<RESTART ABORT {10029531B3}>                                                                                                                                                                    
  [structure-object]                                                                                                                                                                             

Slots with :INSTANCE allocation:                                                                                                                                                                 
  NAME                  = ABORT                                                                                                                                                                  
  FUNCTION              = #<CLOSURE (LAMBDA (&REST SB-IMPL::TEMP) :IN SB-IMPL::TOPLEVEL-REPL) {1..                                                                                               
  REPORT-FUNCTION       = #<FUNCTION (LAMBDA (STREAM) :IN SB-IMPL::TOPLEVEL-REPL) {100014A8BB}>                                                                                                  
  INTERACTIVE-FUNCTION  = NIL                                                                                                                                                                    
  TEST-FUNCTION         = #<FUNCTION (LAMBDA (COND)..                                                                                                                                            
于 2013-03-20T16:08:01.973 回答