是否有“树结构编辑器”?对于 Lisp 来说?

发布于 2024-12-11 15:08:26 字数 280 浏览 0 评论 0原文

我听说 S 表达式可以表示为树;例如 (f 1 (g 2) 3) as

      .
 .  .  .    .
f  1   .      3          [first level]
      g  2               [second level]

有没有一个编辑器(最好是免费的)可以直接编辑这种结构?这将

  1. 避免“所有那些括号”
  2. 展现我一直理解的 lisp 的优雅。

I've heard that S-expressions can be represented as trees; for example (f 1 (g 2) 3) as

      .
 .  .  .    .
f  1   .      3          [first level]
      g  2               [second level]

Is there an editor (preferably free) for editing this kind of structure directly? This would

  1. Avoid "all those parentheses"
  2. Exhibit the elegance I've been understanding of lisp.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

神妖 2024-12-18 15:08:26

S 表达式代表一棵树,而不是相反。您的示例,用换行符格式化:

(f 1
   (g 2)
   3)

它代表以下 cons 树:

    +---+---+   +---+---+   +---+---+   +---+---+
--->| f | ----->| 1 | ----->| ¦ | ----->| 3 |NIL|
    +---+---+   +---+---+   + ¦ +---+   +---+---+
                              v
                            +---+---+   +---+---+
                            | g | ----->| 2 |NIL|
                            +---+---+   +---+---+

这同时也是程序的实际抽象语法树 - 其他语言系列的编译器必须根据复杂的规则构建的东西。

对于编辑,括号是您和您的编辑器在树级别上操作所需的全部内容。在 Emacs 中,它是 paredit-mode,但我猜其他编辑器也有类似的实用程序或插件。

S-expressions represent a tree, not the other way around. Your example, formatted with newlines:

(f 1
   (g 2)
   3)

It represents the following cons tree:

    +---+---+   +---+---+   +---+---+   +---+---+
--->| f | ----->| 1 | ----->| ¦ | ----->| 3 |NIL|
    +---+---+   +---+---+   + ¦ +---+   +---+---+
                              v
                            +---+---+   +---+---+
                            | g | ----->| 2 |NIL|
                            +---+---+   +---+---+

This is at the same time the actual abstract syntax tree of the program—something that compilers for other language families have to construct from intricate rules.

For editing, the parentheses are all you and your editor need to operate on the tree level. In Emacs it is paredit-mode, but I guess that other editors have similar utilities or plugins.

不回头走下去 2024-12-18 15:08:26

据我所知(正如维基百科文章所证实的那样),结构编辑用于Interlisp-D。我不知道目前广泛使用的 Common Lisp 结构编辑器是什么,但也许有一些我不知道的事情。 Pascal J. Bourguignon 有一个 示例您可能想玩一下的网站。 (我没有仔细看)我确实这样做了,但是在 Oxygen 中使用了类似的 XML 内容不久前。

(另外,我不认为 Interlisp 使用它的原因与去掉括号有任何关系,例如,注释可能存在问题。)

As far as I know (and as the Wikipedia article confirms), structure editing was used in Interlisp-D. I am not aware of any structure editor for Common Lisp widely in use today, but maybe there is something I don't know about. There is an example on Pascal J. Bourguignon 's site you may want to play around with. (I didn't take a closer look at it) I did, however use something similar for XML in Oxygen some time ago.

(Also, I don't think the reason Interlisp used this had anything to do with getting rid of the parentheses, and there might be problems with comments, for example.)

千寻… 2024-12-18 15:08:26

emacs 的 ParEdit 模式本质上是一个结构化编辑器。

另外,在他们的论文 、 哥莫尔卡 & Humm 提到了一个为 Eclipse 扩展 CUSP 的研究原型,但我不知道可下载的实现。

The ParEdit mode for emacs is essentially a structured editor.

Also, in their paper, Gomolka & Humm mention a research prototype extending CUSP for Eclipse, but I don't know of a downloadable implementation.

≈。彩虹 2024-12-18 15:08:26

Gingko 作为 lisp 的树结构编辑器

我们正在努力让您用 Gingko 编写 Lisp(通用树结构编辑器)。

从树到源的转换是微不足道的,所以实际上唯一缺少的是更多的深度(Gingko 目前仅限于 3 个级别)。

[这仍然是非常实验性的,所以我很想得到反馈和反馈。 Lisp 专家的意见。]

Gingko as a Tree Structure editor for lisp

We're working on letting you write Lisp with Gingko (a general tree structure editor).

The conversion from tree to source is trivial, so really the only thing missing is more depth (Gingko is currently limited to 3 levels).

[This is still very experimental, so I'd love feedback & input from Lisp experts.]

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