macos 从 Mac 终端编译/运行 Common LIsp

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5302826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:50:20  来源:igfitidea点击:

compile/run Common LIsp from the Mac Terminal

macoslispterminalcommon-lisp

提问by hedgehogrider

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.

有没有办法做到这一点?我一直在使用 Slime 来学习 Lisp,我想开始构建更大的项目,这意味着(我认为)我必须开始编写一些 .lisp 文件。

采纳答案by rmalouf

I think your best bets for Mac Common LISP are the LispWorks Personal Editionor SBCL.

我认为 Mac Common LISP 的最佳选择是LispWorks Personal EditionSBCL

Assuming you've got SBCL installed, you can create a .lisp file using a text editor (emacs would be the traditional choice):

假设您已经安装了 SBCL,您可以使用文本编辑器创建一个 .lisp 文件(emacs 将是传统的选择):

(defun test ()
"Hi!")

Then you can run a lisp interpreter in a shell:

然后你可以在 shell 中运行一个 lisp 解释器:

bash% sbcl
This is SBCL 1.0.29, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (load "test.lisp")

T
* (test)

"Hi!"
* 

The shell could either be a mac terminal window or an inferior lisp interpreterrunning in emacs.

shell 可以是 mac 终端窗口,也可以是在 emacs 中运行的低级 lisp 解释器

回答by Svante

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).

Slime 旨在支持编写 Lisp 文件,包括定义查找、在线文档、名称完成、编译等。也许你应该看看手册,第 3 章(使用粘液模式)。

回答by danlei

I think it is a bit hard to tell what you are really asking for.

我认为很难说出你真正要求的是什么。

You cancompile and load a whole Lisp file in Slime by using C-c C-kin the buffer, and then use it from within the Slime REPL, so you don't even have to run LOADin the REPL.

可以通过C-c C-k在缓冲区中使用,在 Slime 中编译和加载整个 Lisp 文件,然后在 Slime REPL 中使用它,因此您甚至不必LOAD在 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.

然后,如果您想从命令行将 Lisp 程序作为脚本运行,那么从 unices 已知的 shebang 行有一些解决方案可以在 OS X shell 中工作,但这些解决方案因实现而异。

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.

构建可执行文件(然后可以从命令行运行)的一种可能性是将相关代码加载到您的 Lisp 图像中,然后将该图像与加载的代码一起保存。这些图像可能是可执行的,在启动时执行给定的功能(想想main)。这种可能性也因实现而异,因此无需提及您选择的实现,您必须在其文档中查找。

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.

现在,由于您专门询问“构建更大的项目”,我的建议是熟悉系统定义工具。一个 lisp 系统基本上是一种“项目”,一些带有代码、包定义和系统定义的文件。我会给你一个关于ASDF的小例子,它(据我所知)是开源世界中最受欢迎的。

(defsystem my-system
  :name "my-system"
  :version "0.0.1"
  :author "hedgehogrider"
  :license "BSD"
  :description "bla bla bla"
  :serial t
  :components ((:file "packages")
               (:file "code")))

Now, you would put this in an asdfile, say my-system.asd, put your package definitions in packages.lisp, your functionality in code.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.

现在,您可以将它放在一个asd文件中,例如my-system.asd,将您的包定义放在 中packages.lisp,将您的功能放在 中code.lisp,然后,如果您正确设置了 ASDF,您将能够通过按 来在 Slime REPL 中编译和加载您的系统,l my-system。或者,您可以在 REPL 中输入(asdf:oos 'load-op 'my-system)(或者,对于更新版本的 ASDF: (asdf:load-system 'my-system))。

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 in asdf:*central-registry*. One easy solution is to symlink your asdf-files to one central directory, but there are other possibilities. Check the ASDF documentationor other tutorialsto learn more about ASDF.

为了使这个工作,你必须为你的 Lisp 实现安装 ASDF,如果它没有随它一起提供,并且包含你的asdf-files的目录必须放在asdf:*central-registry*. 一种简单的解决方案是将您的asdf-files符号链接到一个中央目录,但还有其他可能性。查看ASDF 文档其他教程以了解有关 ASDF 的更多信息。

回答by Paul Nathan

Yes, you will want to write your own Lisp files instead of relying on images.

是的,您将希望编写自己的 Lisp 文件而不是依赖图像。

I recommend CLISP for OSX for an out-of-the-box experience. It has a nice REPL experience.

我推荐 OSX 的 CLISP 以获得开箱即用的体验。它有很好的 REPL 体验。

Professional development done with F/OSS today generally uses SBCL or CCL.

目前使用 F/OSS 进行的专业开发通常使用 SBCL 或 CCL。