Lisp导入/加载文件 [英] Lisp importing/loading file

查看:159
本文介绍了Lisp导入/加载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Lisp中有没有办法包含其他Lisp文件的代码?

Is there a way in Lisp to include code from other Lisp files?

例如,在C ++中我可以这样做:

For example, in C++ I can do this:

#include <iostream>
#include <string>
#include "myfile.h"
etc...

Python,

import antigravity
import my_module
etc...

是否有等价的Lisp?

Is there a Lisp equivalent?

推荐答案

除了Rainer的回答:

In addition to Rainer's answer:

如果你想加载 ASDF - 系统,使用:

If you want to load ASDF-systems, use:

(asdf:load-system 'my-system)

一些Lisp实现(例如CCL)也允许使用 require 用于加载ASDF系统,但该功能依赖于实现。如果您正在使用Slime,并希望以交互方式加载系统,则可以通过在Slime REPL中键入,l my-system 来执行此操作。

Some Lisp implementations (CCL for example) also allow using require for loading ASDF systems, but that functionality is implementation dependent. If you are using Slime, and want to load a system interactively, you can do so by typing ,l my-system at the Slime REPL.

我想指出的另一件事是,与Python不同,使用 require load 在CL中与包没有任何关系(想想命名空间)。因此,如果您正在加载或要求生活在自己的包中的代码,您将必须使用其导出的符号限定( foo:bar ),或者包含这些包您的代码所在的包((defpackage my-package(:使用cl包 - 您想要使用...)...))。这不仅与Python import s不同,而且与C预处理器 #include s不同,后者仅仅是文本包含物。

Another thing I wanted to point out is that, unlike in Python, using require or load in CL does not have anything to do with packages (think "namespaces"). So, if the code you are loading or requiring lives in its own package, you will either have to use its exported symbols qualified (foo:bar), or include those packages in the package your code lives in ((defpackage my-package (:use cl package-you-want-to-use ...) ...)). This does not only differ from Python imports, but also from C preprocessor #includes, the latter being mere textual inclusions.

这篇关于Lisp导入/加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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