gpt4 book ai didi

common-lisp - 使用 ASDF 加载可选组件

转载 作者:行者123 更新时间:2023-12-02 21:50:12 24 4
gpt4 key购买 nike

如何告诉 ASDF 仅在组件文件存在时才处理该组件文件(以便在组件文件尚不存在时不会生成错误)。

(asdf:defsystem "my-system"
:components ((:file "utilities")
(:file "temp-file" :depends-on ("utilities"))))

我的解决方法是使用读取器宏#。在 (probe-file "temp-file") 上,但无法使其工作。

最佳答案

我认为你真正想做的是让 ASDF 只是警告你,而不是在编译错误期间启动调试器。更改 *compile-file-warnings-behaviour**compile-file-failure-behaviour*,并读取 the section on error handling在手册中。

这个答案的其余部分是如何检查整个系统。您可以将可能要加载的文件打包到它们自己的系统中,并按照下面的方式执行此操作。

来自ASDF Manual section 6.3.8 .

6.3.8 Weakly depends on

We do NOT recommend you use this feature.

所以你无论如何都可以使用它。像这样:

(defpackage :foo-system
(:use :cl :asdf))
(in-package :foo-system)
(defsystem foo
:description "The main package that maybe loads bar if it exists."
:weakly-depends-on (:bar)
:components ((:file "foo")))

简单吧?

以下是他们的建议:

If you are tempted to write a system foo that weakly-depends-on a system bar, we recommend that you should instead write system foo in a parametric way, and offer some special variable and/or some hook to specialize its behaviour; then you should write a system foo+bar that does the hooking of things together.

我从未在野外见过其中的一个,可能是因为这样做会造成可怕的困惑。

(defpackage :bar-system
(:use :cl :asdf))
(in-package :bar-system)
(defsystem bar
:description "The package that maybe exists and is needed by foo."
:components ((:file "bar")))

(defpackage :foo+bar-system
(:use :cl :asdf))
(in-package :foo+bar-system)
(defsystem foo+bar
:version "0.1.0"
:description "Hook together foo and bar."
:author "Spenser Truex <web@spensertruex.com>"
:serial t
:components ((:file "foo+bar")))

(defpackage :foo-system
(:use :cl :asdf))
(in-package :foo-system)
(defsystem foo
:description "The main package that maybe loads bar if it exists."
:depends-on (:foo+bar)
:components ((:file "foo")))

关于common-lisp - 使用 ASDF 加载可选组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56483597/

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