使用相对路径加载文件 [英] Load file with a relative path

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

问题描述

我正在尝试使用相对路径从同一目录中的文件加载Lisp中的文件。

I am trying to load a file in Lisp from a file in the same directory using a relative path.

我的文件结构如下:

repo/
    subdir/
        main.lisp
        test.lisp

main.lisp 中,我有很多函数定义,在 test.lisp 我要测试功能。

In main.lisp I have a number of function definitions, and in test.lisp I want to test the functions.

我尝试使用(load main .lisp)(加载 main) test.lisp 中,以及路径名的多个变体(即,在文件名前包含 ./ ),但两次都出现以下错误(其中< filename> 是传递给加载函数的文件名):

I have tried using (load "main.lisp") and (load "main") in test.lisp, as well as a number of variations on the pathname (i.e., including ./ before the filename) but both times I get the following error (where <filename> is the filename passed to the load function):

函数LISP :: INTERNAL-中的文件错误LOAD:<文件名>

是否可以使用相对对象加载 main.lisp 路径?

Is it possible to load main.lisp using a relative path?

可能值得注意的是,我正在运行 CMUCL ,然后在Sublime Text 3内使用 SublimeREPL 执行代码。

It may be worth noting that I am running CMUCL and executing the code using SublimeREPL inside of Sublime Text 3.

推荐答案

加载文件时,变量 * LOAD-PATHNAME * 绑定到加载文件的路径名,并 * LOAD-TRUENAME * 为其真实名称。

When a file is being loaded, the variable *LOAD-PATHNAME* is bound to the pathname of the file being loaded, and *LOAD-TRUENAME* to its truename.

因此,要加载文件文件与当前正在加载的文件位于同一目录中,您可以说

So, to load a file in the same directory with the file currently being loaded, you can say

(load (merge-pathnames "main.lisp" *load-truename*))

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

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