在Common Lisp中使用外部库或程序包的示例 [英] example of using external libraries or packages in Common Lisp

查看:61
本文介绍了在Common Lisp中使用外部库或程序包的示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Common Lisp, quicklisp is a popular library management tool. I'm going to use that tool and I'm going to try and use CL-WHO. I use the SBCL 1.0.57 implementation. I'm going to answer my own question below.

作为一个初学者,尚不清楚ASDF和quicklisp实际如何协同工作.因此,目前尚不清楚如何在外部源文件中实际使用通过quicklisp下载的软件包或库.quicklisp FAQ(至少在此刻)无济于事.在python中,它非常简单:您只需输入"import somemodule",就可以了.CL + quicklisp是否具有等效功能?

As a beginner, it's not clear how ASDF and quicklisp actually work together. And so it's not clear how to actually use packages or libraries that you've downloaded through quicklisp in an external source file. The quicklisp FAQ, at least at this moment, does not help. In python, it's incredibly simple: you can just put 'import somemodule' and life is great. Is there an equivalent for CL+quicklisp?

如果您进行搜索,则会发现许多结果.以下是一些我发现的最相关的内容:

If you search, you find many results. Here are some of the most relevant ones I've found:

Lisp导入/加载文件

如何使用quicklisp安装的软件包?

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

When I was reading through these originally, at least one question came to mind: do I actually have to care about ASDF if I'm using quicklisp? Quicklisp seems to be a higher level management tool. Other people suggest using quickproject. But is that really necessary?

推荐答案

与Python导入的类比是系统定义...嗯,这是一个非常宽松的类比,但是,这是要走的路.您可以在系统定义中声明依赖项,然后在源代码中期望它存在,因此,如果以后再引用外来代码的位,则只需执行此操作即可.

The analogy to Python's imports is the system definition... well, this is a very loose analogy, but, it's the way to go. You declare dependencies in the system definition and then in source code you expect it to be there, so that if you later refer to the bits of the foreign code, you just do it.

例如.在系统定义中,您可能会拥有:(通常它将位于 my-program.asd 文件中)

Eg. in the system definition you might have: (usually it would be in my-program.asd file)

(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 对您的程序可用,例如:

Later on in your code you just assume that the some-external-package is available to your program, e.g.:

(some-external-package:exported-symbol)

应该工作.(您的代码"是您在组件中指定的some-source-file.lisp.)

should just work. ("Your code" is the some-source-file.lisp, you've specified in the components).

这是ASDF 在将此文件放置在在这里解释.

After you have this file in the place where ASDF might find it*, assuming you have ASDF installed (available to your Lisp, SBCL comes bundled with it), you'd load this system using (asdf:load-system :my-program) Explained here.

*-一种快速的测试方法

* - A quick way to test it would be to do

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

这篇关于在Common Lisp中使用外部库或程序包的示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆