gpt4 book ai didi

linux - 在 Common Lisp 中使用外部库或包的例子

转载 作者:太空狗 更新时间:2023-10-29 11:15:17 25 4
gpt4 key购买 nike

在Common Lisp中,quicklisp是一种流行的图书馆管理工具。我将使用该工具并尝试使用 CL-WHO。我使用 SBCL 1.0.57 实现。我将在下面回答我自己的问题。

作为初学者,不清楚 ASDF 和 quicklisp 实际上是如何协同工作的。因此,不清楚如何在外部源文件中实际使用通过 quicklisp 下载的包或库。 quicklisp 常见问题解答,至少在此刻,没有帮助。在 Python 中,它非常简单:你只需输入“导入某个模块”,一切就都很棒了。是否有 CL+quicklisp 的等效项?

如果您搜索,您会找到很多结果。以下是我发现的一些最相关的内容:

Lisp importing/loading file

How to use packages installed by quicklisp?

当我最初阅读这些内容时,至少想到了一个问题:如果我使用的是 quicklisp,我真的需要关心 ASDF 吗? Quicklisp 似乎是一个更高级别的管理工具。其他人建议使用 quickproject。但这真的有必要吗?

最佳答案

与 Python 的导入类比的是系统定义...好吧,这是一个非常宽松的类比,但是,这是要走的路。您在系统定义中声明依赖项,然后在源代码中您希望它在那里,这样如果您稍后引用外部代码的位,您就可以这样做。

例如。在系统定义中,您可能有:(通常在 my-program.asd 文件中)

(defsystem :my-program
:version "0.0.1"
:serial t
:description "My program"
:components ((:file "some-source-file"))
;; `some-external-package' here is the "import", i.e. here you
;; declared that you will be using code from this package.
;; ASDF will generally "know" how to get the code of that package
;; from here on. But if it doesn't, then there are ways to "help it"
;; similar to how in Python there's a procedure to prepare your local
;; files to be used by easy_install
:depends-on (:some-external-package))

稍后在您的代码中,您只需假设 some-external-package 可用于您的程序,例如:

(some-external-package:exported-symbol)

应该可以正常工作。 (“您的代码”是您在组件中指定的 some-source-file.lisp)。

这是 ASDF documentation on how to define systems

将此文件放在where ASDF might find it 位置之后*,假设您安装了 ASDF(可用于您的 Lisp,SBCL 与它捆绑在一起),您将使用 (asdf:load-system :my-program) Explained here. 加载该系统

* - 一个快速测试它的方法是做

(push "/path/to/your/system/definition/" asdf:*central-registry*)

关于linux - 在 Common Lisp 中使用外部库或包的例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15303566/

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