从 Mac 终端编译/运行 Common LIsp

发布于 2024-10-21 15:06:42 字数 81 浏览 1 评论 0原文

有办法做到这一点吗?我一直在使用 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 技术交流群。

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

发布评论

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

评论(4

枕梦 2024-10-28 15:06:42

我认为 Mac Common LISP 的最佳选择是 LispWorks 个人版SBCL

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

(defun test ()
"Hi!")

然后您可以在 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!"
* 

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

(defun test ()
"Hi!")

Then you can run a lisp interpreter in a shell:

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 interpreter running in emacs.

比忠 2024-10-28 15:06:42

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

寒江雪… 2024-10-28 15:06:42

我认为很难说出你真正想要什么。

可以通过在缓冲区中使用Cc Ck在Slime中编译并加载整个Lisp文件,然后在Slime REPL中使用它,所以您甚至不需要在 REPL 中运行 LOAD

然后,如果您想从命令行将 Lisp 程序作为脚本运行,则可以在 unice 中找到可以在 OS X shell 中工作的 shebang 行解决方案,但这些解决方案因实现而异。

构建可执行文件(然后可以从命令行运行)的一种可能性是将相关代码加载到 Lisp 映像中,然后使用加载的代码保存该映像。这些映像可以是可执行的,在启动时执行给定的函数(想想main)。这种可能性对于实现也有所不同,因此在不提及您选择的实现的情况下,您将必须在其文档中查找它。

现在,既然您具体询问“构建更大的项目”,我的建议是熟悉系统定义工具。 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")))

现在,您可以将其放入 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 run LOAD 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.

(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 asd file, 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.

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 documentation or other tutorials to learn more about ASDF.

醉城メ夜风 2024-10-28 15:06:42

是的,您会想要编写自己的 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.

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