小编use*_*072的帖子

公共列表:在不同的包中使用handler-case

我有以下lisp代码:

;;; hop.lisp

(defpackage #:hop
  (:use #:cl ))

(in-package :hop)
(export 'hop)

(defun hop ()
  (restart-case
      (error "Hop")
    (hop ()
      (format t "hop"))))
Run Code Online (Sandbox Code Playgroud)

我定义一个总是失败但提供重启的虚函数:hop.

在另一个包中,在此文件中:

;;; hip.lisp

(defpackage #:hip
  (:use #:cl #:hop))

(in-package :hip)

(defun dhip ()
  (hop:hop))

(defun hip ()
  (handler-case
      (hop:hop)
    (error (e)
      (declare (ignore e))
      (format t "restarts: ~a~%" (compute-restarts))
      (invoke-restart 'hop))))
Run Code Online (Sandbox Code Playgroud)

我定义了从第一个包中调用函数(hop)的函数(hip)和(dhip).

当我打电话(dhip)时,sbcl给我一个提示,我可以选择使用我的重启跃点重新启动:

Hop
   [Condition of type SIMPLE-ERROR]

Restarts:
 0: [HOP] HOP
 1: [RETRY] Retry SLIME REPL evaluation request.
 2: [*ABORT] Return to SLIME's top level. …
Run Code Online (Sandbox Code Playgroud)

restart common-lisp condition-system

4
推荐指数
1
解决办法
139
查看次数

标签 统计

common-lisp ×1

condition-system ×1

restart ×1