如何在 Prolog 中包含 .pl 文件?

发布于 2024-09-30 18:36:45 字数 31 浏览 1 评论 0原文

我想包含另一个源文件中的代码。有谁知道该怎么做?

I'd like to include code from another source file. Does anyone know how to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别在捏我脸啦 2024-10-07 18:36:45

如果您的文件名为 foo.pl,您可以使用

:- [foo].

or 包含它,等效地并且更明确一点

:- consult(foo).

,或者,如果您担心它可能会在较大的应用程序中加载多次

:- ensure_loaded(foo).

,或者,如果您正在使用成熟的模块

:- use_module(foo).

尽管 Prolog 之间最后一个谓词的确切名称有所不同版本。

If your file is called foo.pl, you can include it using

:- [foo].

or, equivalently and a bit more explicit

:- consult(foo).

or, if you're worried it may be loaded several times in a larger app

:- ensure_loaded(foo).

or, if you're using full-blown modules

:- use_module(foo).

though the exact name of the last predicate differs between Prolog versions.

缪败 2024-10-07 18:36:45

如果您想按字面意思包含该文件 - 类似于 #include,请使用
:- 包括('file.pl')。

大多数时候最好使用以下方式构建程序
不过,模块。

If you want to include the file literally - similar to #include, use
:- include('file.pl').

Most of the time it is preferable to structure your program using
modules, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文