'error' 过程在 plt-r5rs 中未定义

'error' procedure is undefined in plt-r5rs

我将此文件命名为 myprog.scm:

(error "Not found!")

运行使用plt-r5rs myprog.scm的程序报错:

error: undefined;
 cannot reference undefined identifier
  context...:
   /usr/share/racket/pkgs/r5rs-lib/r5rs/run.rkt: [running body]

显然,plt-r5rs 没有定义 error 过程。

Why did the authors of plt-r5rs not define the error procedure?

看来 The Revised5 Report on the Algorithmic Language Scheme does not define a procedure named error. The initial environment created by plt-r5rs contains only the values and syntactic forms defined in the report (except for a handful of implementation-specific forms listed in the docs#%require 一样,根据 R5RS).

,它们不是合法的标识符

How can I define or import an error procedure so that my program can run? Perhaps there's a way to import SRFI-23 Error reporting mechanism?

你可能知道,R5RS 也没有定义模块系统,所以没有可移植的方式来导入任何东西。具体来说,对于 plt-r5rs,此版本的程序有效:

(#%require srfi/23)
(error "Not found!")

当然,如果您已经依赖 plt-r5rs 的详细信息,我建议您只使用 Racket,或者至少使用 R6RS.