真正最小的口齿不清

发布于 2024-08-30 19:50:15 字数 147 浏览 11 评论 0原文

要使一种语言成为图灵完备且是 lisp 变体,所需的最小原语集是什么?

看起来像 car、cdr 和一些流量控制以及 REPL 的东西就足够了。如果有这样的清单就好了。

假设只有 3 种数据类型:整数、符号和列表。(就像 picolisp 中一样)

What is the minimum set of primitives required such that a language is Turing complete and a lisp variant?

Seems like car, cdr and some flow control and something for REPL is enough. It be nice if there is such list.

Assume there are only 3 types of data, integers, symbols and lists.(like in picolisp)

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

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

发布评论

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

评论(4

风轻花落早 2024-09-06 19:50:15

lambda 演算是图灵完备的。它有一个原语 - lambda。将其转换为 Lisp 语法非常简单。

The lambda calculus is turing complete. It has one primitive - the lambda. Translating that to a lisp syntax is pretty trivial.

灼疼热情 2024-09-06 19:50:15

Lisp FAQ 对此进行了很好的讨论。这取决于您对基元的选择。 McCarthy原来的《LISP 1.5程序员手册》做到了,用了五个函数:CAR、CDR、CONS、EQ和ATOM。

There's a good discussion of this in the Lisp FAQ. It depends on your choice of primitives. McCarthy's original "LISP 1.5 Programmer's Manual" did it with five functions: CAR, CDR, CONS, EQ, and ATOM.

远昼 2024-09-06 19:50:15

我相信最小集是约翰·麦卡锡在原始论文中发表的内容。

Lisp 的根源

代码

I believe the minimum set is what John McCarthy published in the original paper.

The Roots of Lisp.

The code.

℡寂寞咖啡 2024-09-06 19:50:15

真正了解这一点的最佳方法是实施它。我用了 3 个夏天的时间创建了 Zozotez,它是一个运行在 Brainfuck

我试图找出我需要的东西,在论坛上你会发现一个线程,上面写着 你只需要 lambda。因此,如果你愿意的话,你可以用 lambda 演算创建一个完整的 LISP。我发现它很有趣,但如果你想要一些最终会产生副作用并且在现实世界中有效的东西,那么这几乎不是一个可行的方法。

对于图灵完备的 LISP,我使用了 Paul Grahams 对 McCarthy 论文的解释,你真正需要的是:

  • 符号-evaluation
  • 特殊形式 quote
  • 特殊形式 if (或 cond)
  • 特殊形式 lambda (类似于 quote)
  • function eq
  • functionatom
  • function cons
  • function car
  • function cdr
  • function-dispatch (基本上应用但实际上不暴露给系统,因此它处理一个列表,其中第一个元素是一个函数)

那就是 10。除此之外,要拥有一个可以测试的实现,而不仅仅是在绘图板上:

  • function read
  • function write

那就是 12。在我的 Zozotez 我还实现了 setflambda (匿名宏,如 lambda)。我可以给它提供一个实现任何动态绑定 Lisp(Elisp、picoLisp)的库,但文件 I/O 除外(因为底层 BF 除了 stdin/stdout 之外不支持它)。

我建议任何人都用 LISP(不是 LISP) 实现 LISP1 解释器,以充分理解语言是如何实现的。 LISP 的语法非常简单,因此它是一个很好的起点。对于所有其他编程语言,实现解释器的方式非常相似。例如。在 SICP 视频中,向导为一种逻辑语言,但其结构和实现方式与 Lisp 解释器非常相似,尽管这种语言与 Lisp 完全不同。

The best way to actually know this for sure is if you implement it. I used 3 summers to create Zozotez which is a McCarty-ish LISP running on Brainfuck.

I tried to find out what I needed and on a forum you'll find a thread that says You only need lambda. Thus, you can make a whole LISP in lambda calculus if you'd like. I found it interesting, but it's hardly the way to go if you want something that eventually has side effects and works in the real world.

For a Turing complete LISP I used Paul Grahams explanation of McCarthy's paper and all you really need is:

  • symbol-evaluation
  • special form quote
  • special form if (or cond)
  • special form lambda (similar to quote)
  • function eq
  • function atom
  • function cons
  • function car
  • function cdr
  • function-dispatch (basically apply but not actually exposed to the system so it handles a list where first element is a function)

Thats 10. In addition to this, to have a implementation that you can test and not just on a drawing board:

  • function read
  • function write

Thats 12. In my Zozotez I implemeted set and flambda (anonymous macroes, like lambda) as well. I could feed it a library implementing any dynamic bound lisp (Elisp, picoLisp) with the exception of file I/O (because the underlying BF does not support it other than stdin/stdout).

I recommend anyone to implement a LISP1-interpreter, in both LISP and (not LISP), to fully understand how a language is implemented. LISP has a very simple syntax so it's a good starting point. For all other programming languages how you implement an interpreter is very similar. Eg. in the SICP videos the wizards make an interpreter for a logical language, but the structure and how to implement it is very similar to a lisp interpreter even though this language is completely different than Lisp.

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