启动预先存在的重启的最快,最简单的方法是什么?

时间:2013-03-19 03:42:23

标签: error-handling common-lisp

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

如果我去:

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重试确实可以正常工作;感谢汉斯和斯万特指出这一点。其他 - 重试,终止线程等 - 所有错误输出。

我也试过在调试器中点击e并直接运行INVOKE-RESTART。同样的结果有一个例外:this answer中的低级示例就像我认为的那样:

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

返回到没有投诉的提示。只有在重启菜单中手动选择时,高级示例才会正确重启。

4 个答案:

答案 0 :(得分:3)

输出中重启1前面的星号表示SLIME的[q] uit命令将调用此重启。重启的名称是'ABORT,所以为了调用它,请使用:

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

答案 1 :(得分:2)

retry再次尝试评估同一个变量。由于您没有绑定它,它仍然是未绑定的。

你可能会更幸运
(handler-case
    whatever
  (unbound-variable (e)
    (setq whatever 42)
    (invoke-restart 'swank::retry)))

应返回42。

答案 2 :(得分:2)

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

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

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

答案 3 :(得分: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)..