从 Mac 终端编译/运行 Common LIsp
有办法做到这一点吗?我一直在使用 Slime 来学习 Lisp,并且我想开始构建更大的项目,这意味着(我认为)我必须开始编写一些 .lisp 文件。
Is there a way to do this? I've been using Slime to learn Lisp, and I would like to start building larger projects which means (I think) that I would have to start writing some .lisp files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为 Mac Common LISP 的最佳选择是 LispWorks 个人版 或 SBCL。
假设您已经安装了 SBCL,您可以使用文本编辑器创建 .lisp 文件(emacs 将是传统选择):
然后您可以在 shell 中运行 lisp 解释器:
shell 可以是 mac 终端窗口,也可以是劣质 lisp 解释器 在 emacs 中运行。
I think your best bets for Mac Common LISP are the LispWorks Personal Edition or SBCL.
Assuming you've got SBCL installed, you can create a .lisp file using a text editor (emacs would be the traditional choice):
Then you can run a lisp interpreter in a shell:
The shell could either be a mac terminal window or an inferior lisp interpreter running in emacs.
Slime 旨在支持编写 Lisp 文件,包括定义查找、在线文档、名称补全、编译等。也许你应该看一下手册,第 3 章(使用 slime-mode)。
Slime is designed to support writing Lisp files, including definition finding, online documentation, name completion, compilation, and more. Perhaps you should take a look at the manual, chapter 3 (using slime-mode).
我认为很难说出你真正想要什么。
您可以通过在缓冲区中使用
Cc Ck
在Slime中编译并加载整个Lisp文件,然后在Slime REPL中使用它,所以您甚至不需要在 REPL 中运行LOAD
。然后,如果您想从命令行将 Lisp 程序作为脚本运行,则可以在 unice 中找到可以在 OS X shell 中工作的 shebang 行解决方案,但这些解决方案因实现而异。
构建可执行文件(然后可以从命令行运行)的一种可能性是将相关代码加载到 Lisp 映像中,然后使用加载的代码保存该映像。这些映像可以是可执行的,在启动时执行给定的函数(想想
main
)。这种可能性对于实现也有所不同,因此在不提及您选择的实现的情况下,您将必须在其文档中查找它。现在,既然您具体询问“构建更大的项目”,我的建议是熟悉系统定义工具。 Lisp 系统基本上是一种“项目”,一些包含代码、包定义和系统定义的文件。我会给你一个 ASDF 的小例子,这是(据我所知)开源世界中最受欢迎的一种。
现在,您可以将其放入
asd
文件中,例如my-system.asd
,将包定义放入packages.lisp
中,您的功能在code.lisp
中,然后,如果您正确设置了 ASDF,您就可以通过按,l my-system
在 Slime REPL 中编译和加载您的系统。或者,您可以输入(asdf:oos 'load-op 'my-system)
(或者,对于更新版本的 ASDF:(asdf:load-system 'my-system)< /code>) 在 REPL 中。
为了使其工作,您必须为您的 Lisp 实现安装 ASDF(如果未附带),并且包含
asdf
文件的目录必须放入asdf:*中央注册表*
。一种简单的解决方案是将您的asdf
文件符号链接到一个中央目录,但还有其他可能性。查看 ASDF 文档 或 其他教程了解有关 ASDF 的更多信息。I think it is a bit hard to tell what you are really asking for.
You can compile and load a whole Lisp file in Slime by using
C-c C-k
in the buffer, and then use it from within the Slime REPL, so you don't even have to runLOAD
in the REPL.Then, there are solutions for shebang lines known from unices that will work in the OS X shell, if you want to run your Lisp programs as scripts from the command line, but those differ from implementation to implementation.
A possibility for building executables, which then can be run from the command line, is loading the relevant code into your Lisp image, then saving that image with the loaded code. Those images may be made executable, executing a given function on startup (think
main
). This possibility also differs for implementations, so without mentioning your implementation of choice, you will have to look it up in its documentation.Now, since you are asking about "building larger projects" specifically, my advice would be to get acquainted with a system definition facility. A lisp system basically is a kind of "project", a few files with code, package definitions, and a system definition. I will give you a little example for ASDF, which is (as far as I can tell) the most popular one in the open source world.
Now, you would put this in an
asd
file, saymy-system.asd
, put your package definitions inpackages.lisp
, your functionality incode.lisp
, and then, given you set up ASDF properly, you would be able to compile and load your system in the Slime REPL by pressing,l my-system
. Alternatively, you could enter(asdf:oos 'load-op 'my-system)
(or, for more recent versions of ASDF:(asdf:load-system 'my-system)
) at the REPL.In order to make this work, you will have to install ASDF for your Lisp implementation, if it is not shipped with it, and the directory containing your
asdf
-files will have to be put inasdf:*central-registry*
. One easy solution is to symlink yourasdf
-files to one central directory, but there are other possibilities. Check the ASDF documentation or other tutorials to learn more about ASDF.是的,您会想要编写自己的 Lisp 文件,而不是依赖图像。
我推荐使用 CLISP for OSX 以获得开箱即用的体验。它有很好的 REPL 体验。
如今使用 F/OSS 进行的专业开发通常使用 SBCL 或 CCL。
Yes, you will want to write your own Lisp files instead of relying on images.
I recommend CLISP for OSX for an out-of-the-box experience. It has a nice REPL experience.
Professional development done with F/OSS today generally uses SBCL or CCL.