gpt4 book ai didi

error-handling - 在SBCL中使用[Take New]重新启动

转载 作者:行者123 更新时间:2023-12-03 07:40:52 27 4
gpt4 key购买 nike

当我尝试以导致名称冲突的方式在SBCL中重新定义软件包时,重新启动时出现NAME-CONFLICT错误

 0: [KEEP-OLD] Keep symbols already accessible FOO (shadowing others).
1: [TAKE-NEW] Make newly exposed symbols accessible in FOO, uninterning old ones.
2: [RESOLVE-CONFLICT] Resolve conflict.
3: [RETRY] Retry SLIME REPL evaluation request.
4: [*ABORT] Return to SLIME's top level.
5: [ABORT] Abort thread (#<THREAD "new-repl-thread" RUNNING {10060E47B3}>)

我想写一些可以自动重启 TAKE-NEW的东西,这样我就可以做
(force (defpackage :foo (:use :cl :bar :baz :mumble)))

其结果应与调用 defpackage相同,然后手动调用 TAKE-NEW restart。问题是,
CL-USER> (handler-case 
(defpackage :foo (:use :cl :bar :baz :mumble))
(error (e) (compute-restarts e)))
(#<RESTART SWANK::RETRY {1006DC40F3}> #<RESTART ABORT {10068007E3}>
#<RESTART ABORT {10060C7F93}>)
CL-USER>

我似乎无法访问该特定的重新启动。正如我尝试调用它时所确认的:
CL-USER> (handler-case 
(defpackage :foo (:use :cl :bar :baz :mumble))
(name-conflict (e) (invoke-restart 'take-new)))

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

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

有任何想法吗?

最佳答案

handler-case在将控制权转移给处理程序之前退出重新启动的范围;您需要handler-bind。构造之间的另外两个区别是handler-bind具有不同的语法(如下所示),并且handler-bind不传递控制权-也就是说,对于handler-bind处理程序返回其值需要显式传递控制权,例如使用return-frominvoke-restart

类似于以下内容的东西应该起作用:

(handler-bind ((sb-ext:name-conflict
(lambda (c)
(when (find-restart 'sb-impl::take-new c)
(invoke-restart 'sb-impl::take-new)))))
(defpackage :foo (:use :mumble)))

关于error-handling - 在SBCL中使用[Take New]重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25773251/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com