您可以使用 emacs 以 common lisp 编程吗?

Can you use emacs to program in common lisp?

在我的 lisp 编程课程中,我使用了 lispworks IDE 试用版, 这是一个非常好的 IDE 但它仍然是试用版。 我搜索了一个新的 IDE。 我看到了这个视频 https://www.youtube.com/watch?v=VnWVu8VVDbI

其中他使用 slime sbcl 和 quicklisp 在 emacs 上使用 common lisp 进行编程。

我的问题是这怎么可能?emacs 不是带有它自己的 lisp 方言,即 Emacs lisp,还是它们彼此分开?

Emacs is an extensible editor (scriptable in Elisp). Read its documentation.

slime-mode (written in Elisp on emacs side, and in Common Lisp on your Lisp system's side) is able to interact with Common Lisp implementations. But you need to install that. Read the documentation of slime。一些 Linux 发行版正在打包粘液(例如 Debian 有一些 slime 包)。

Emacs 有许多其他模式(即扩展,在 Elisp 中提供)能够与各种其他编程语言实现和其他应用程序(shell、电子邮件、版本控制等)交互。

顺便说一句,Common Lisp HyperSpec is freely available. Read it. And SBCL is also documented

您不需要任何 IDE 来使用 SBCL(或 Clisp, or most Common Lisp implementations....). You can use the REPL (inside of emacs or outside of it) and perhaps some editor (e.g. emacs -without even slime-, vim, gedit, ....). When I try some simple code with SBCL, I don't use SLIME (just the REPL, perhaps copy/paste from some editor, and editing a Lisp file then load-ing in Lisp). SLIME is convenient, but is a luxury that you can avoid. However, it is more easy to you to use some editor capable of matching parenthesis (and of skipping lisp comments). But you could code some Common Lisp program -even with many thousands of lines and several dozens of files- even with an editor as simplistic as Notepad on Windows(或 Leafpad 或 nano 在 Linux 上)。你的编辑器不需要 "know" Lisp(例如,有一些模式,或者一些语法变体),因为 lisp 语法非常规则和简单。

请注意,编程语言是一种规范(在一些技术报告中给出,通常是英文 - HyperSpec)并且不应被其实现混淆(例如一些软件,如 SBCL 或 Clisp)。

我实际上用 emacs 编写了我所有的 Lisp 程序,但没有使用 slime。并且我开发了一个Lisp方言(GCC MELT) and implemented it -it is free software that I abandoned, but you can still download it- with emacs but without using Slime. So Slime is really not a requirement, even to code a Lisp program of dozens of thousands of lines. Slime is a luxury you can avoid. The Lisp-mode的emacs已经绰绰有余了(甚至编写一个几千行Common Lisp的程序)。

PS。我用 Common Lisp 编写的最大程序是 GCC MELT 的预引导原始编译器,自从我 bootstrapped GCC MELT 我已经失去了所有那个大程序(因为我不再需要它了)。 IIRC 那个东西——prebootstrap MELT——有几十万行 Common Lisp。 GCC MELT 有超过 120KLOC。

PPS。 如果您是新手,我实际上建议 不要 使用 Common Lisp 中的任何 IDE。只使用 REPL 和一些编辑器(当然还有一个很好的 Common Lisp 实现,比如 SBCL)。把粘液留给 Lisp 专家。仅当您足够流利地使用 Common Lisp(及其 REPL)时才开始使用 slime。

设置 Emacs 和 SBCL 可能会花费您一些时间。

更新:

现在,我不会回答“portacle”或“lispbox”but Roswell as I explain here

上一个回答:

我强烈推荐你portacle - so to say the newer/younger brother of lispbox。 Lispbox 是为 'out of the box'-to lisp 环境创建的,使用安装了 slime-mode 的 emacs,很容易与 sbcl 和 quicklisp-installed 连接(供 Peter Seibel 的 'Practical Common Lisp' 读者使用)- 一种 emacs-set-up -for-Lisp(或从 Lisp 初学者程序员的角度来看的 batteries-included-emacs)。 我一直在寻找 Lispbox 的这个“更新”——虽然同时手动安装了 sbcl 和 quicklisp 和 slime——实际上我认为 Lispbox 站点应该 link 并提示 portacle 因为这是 Lispbox 的最新版本- 它会节省我的时间。 Lisp 社区应该传播有关 portacle 的信息。 (两者都为您提供现成的 emacs,然后连接到 sbcl 并且还安装了 quicklisp - Lisp 的 quicklisp 就像 Python 的 pip,一个包管理器,您可以通过它从一个包中提取和安装 Lisp 包中央存储库 - 或者像 emacs lisp 的 melpa)。 (quicklisp 的核心是 asdf,一个老的包管理器,但现在没有人直接使用 asdf 安装包,而是通过 quicklisp 安装)。

对于 Windows 用户,我强烈推荐 lispstick which works (in contrast to the current version of portacle for Windows ... I hope they fix it). The author also wrote a nice book(2016 年,但使用德语)。

为了更轻松地进入非常复杂的 emacs,我也尝试了几次以适应它,我强烈建议您 Derek Banas' video tutorial on emacs which is one of the best intro-level tutorial I found for this topic. Also his tutorial for common lisp 可能会给您一个良好的开端。 我总结了一些我在 emacs 中编写 common lisp 时经常使用的键绑定(一组最小的键绑定)。它真的很小。谁发现的多,也可以给我更多的小费。 Here is the link to a very minimal emacs/SLIME cheat sheet for lisp beginner programmers

如果您真的开始使用 Lisp 编程,Common Lisp HyperSpec 会很有帮助 - 我想说,这是一个必要的工具 - 还有 Edi Weitz 发起的 Lisp 的 Cookbook 页面以及他的食谱书常见的 Lisp。 然而,由于 Lisp 与所有 C 派生的语言都非常不同,我强烈建议您从 sth 开始,这将向您解释更多 lisp 是什么以及它是如何工作的。 Peter Seibel 的 Practical Common Lisp 和 Conrad Barski 的 Land of Lisp 的组合对我来说是首发。但是,尽管作者确实做得很好,但我认为对于 C 派生语言程序员到 Lisp 的易于阅读和流畅的介绍仍然有待编写。

顺便说一句,如果你觉得 vim 更容易使用,有一个很好的方法可以在 emacs 中使用 vim 快捷方式 - 邪恶模式 - 甚至更好和神奇的是 Spacemacs 除了 vim 快捷方式——它们访问功能的非常具体的方式——主要是从按下 space 按钮开始(因此得名 spacemacs)。它是一个开源项目。

不幸的是,没有适合 lisp 新手的类似 Portacle 的内置电池 spacemacs。但也许我们中的一些人会在不久的将来建立 :) 。 Spacemacs 太棒了!

对于 emacs:我为初学者写下了 emacs 简约命令 in my GitHubGist

是的,Emacs 是 "go to" Common Lisp 编辑器 :)

我们仍然可以使用更多的编辑器:https://lispcookbook.github.io/cl-cookbook/editor-support.html Atom and Sublime don't have great support though (no interactive debugger yet, even if it's in development for Atom). Lem 是一个用 Common Lisp 编写的 Common Lisp 编辑器,还有其他模式(Go 模式,目录模式,...)。它存在于控制台并有一个 Electron 接口。

这是关于如何安装 Lisp 实现和 Quicklisp 的最新指南:https://lispcookbook.github.io/cl-cookbook/getting-started.html(windows 可能不完整)。

其他不错的 Lisp 资源:

尽管这个问题已经有一些很好的答案,但我想在这里添加一个我自己的答案,主要是提到在 Emacs 中开发 Common Lips 的 SLIME 的一个很好的替代品。

SLY 是 SLIME 的一个分支,包含以下改进:

  • 基于Emacs自身的全功能完全重新设计的REPLcomint.el
  • 通过新的 sly-stickers contrib 进行实时代码注释
  • 一致的交互式按钮界面。一切都可以复制到REPL。
  • 不需要额外的包来使用 company(一个流行的(代码)完成包)
  • 默认情况下启用贡献,并按需加载 ASDF
  • 支持 NAMED-READTABLESmacrostep.el 和 quicklisp

SLY 跟踪 SLIME 的错误修复及其所有熟悉的功能(调试器、检查器、外部参照等)仍然可用,但集成度更高。

在我看来,如今 SLY 是在 Emacs 下开始使用 Common Lisp 的最佳方式,所以我鼓励人们检查一下。