在Common Lisp中,quicklisp是一种流行的图书馆管理工具。我将使用该工具,我将尝试使用CL-WHO。我使用SBCL 1.0.57实现。我将在下面回答我自己的问题。
作为初学者,目前尚不清楚ASDF和quicklisp如何实际协同工作。因此,目前尚不清楚如何在外部源文件中实际使用通过quicklisp下载的软件包或库。 quicklisp常见问题解答,至少在这个时刻,没有帮助。在python中,它非常简单:你可以放入'import somemodule',生活很棒。是否有CL + quicklisp的等价物?
如果您搜索,您会发现很多结果。以下是我发现的一些最相关的内容:
How to use packages installed by quicklisp?
当我最初阅读这些内容时,至少有一个问题浮现在脑海中:如果我使用的是quicklisp,我是否真的需要关心ASDF? Quicklisp似乎是一个更高级别的管理工具。其他人建议使用quickproject。但真的是否必要?
答案 0 :(得分:2)
Python的导入类比是系统定义......嗯,这是一个非常宽松的类比,但是,它是要走的路。你在系统定义中声明依赖关系,然后在源代码中声明它们在那里,所以如果你以后引用外部代码的位,你就可以了。
EG。在系统定义中你可能有:(通常它会在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)
{{加载此系统3}}
* - 测试它的快速方法是
(push "/path/to/your/system/definition/" asdf:*central-registry*)
答案 1 :(得分:0)
通过quicklisp页面上的说明下载cl-who并运行:
#!/usr/bin/sbcl --script
(load "~/quicklisp/setup.lisp")
(ql:quickload "asdf")
(asdf:load-system 'cl-who)
(with-open-file (*standard-output* "out.html" :direction :output)
(cl-who:with-html-output (*standard-output* nil :indent t)
(:html
(:head
(:title "Test page"))
(:body
(:p "CL-WHO is really easy to use")))))
对于初学者,或者一个非常懒惰的人来说,没有理由要在顶部写3行而不是只写一行(比如在python中)。