构建 LISP 机器需要多少个原语?十个、七个还是五个? [英] How many primitives does it take to build a LISP machine? Ten, seven or five?

查看:17
本文介绍了构建 LISP 机器需要多少个原语?十个、七个还是五个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个站点上,他们说有 10 个 LISP 原语.原语是:atom、quote、eq、car、cdr、cons、cond、lambda、label、apply.

On this site they say there are 10 LISP primitives. The primitives are: atom, quote, eq, car, cdr, cons, cond, lambda, label, apply.

http://hyperpolyglot.wikidot.com/lisp#ten-primitives

Stevey 估计有七个(或五个):

Stevey reckons there are seven (or five):

这是 LISP 思想纯洁性的一部分:您只需要七个(或者是它五个?)原语来构建完整的机器.http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html

Its part of the purity of the idea of LISP: you only need the seven (or is it five?) primitives to build the full machine. http://steve-yegge.blogspot.com/2006/04/lisp-is-not-acceptable-lisp.html

构建 LISP 机器的最少原语数量是多少(即可以在 LISP 代码上运行 eval/value 函数的东西)?(他们是哪些?)

What is the minimum number of primitives to build a LISP machine (ie something that can run an eval/value function on LISP code)? (And which ones are they?)

(我可以理解你可以没有atom、label和apply)

(I can understand you could live without atom, label and apply)

推荐答案

Basic Predicates/F-functions

McCarthy基本 S 函数和谓词 分别是:

  1. 原子

这是必要的,因为 car 和 cdr 只为列表定义,这意味着如果给 car 一个原子,你不能指望任何类型的答案来表明发生了什么.

Which was necessary because car and cdr are defined for lists only, which means you cannot count on any sort of answer to indicate what was happening if you gave car an atom.

eq

用于测试原子之间的相等性.

For testing equality between atoms.

汽车

用于返回 cons 单元格的前半部分(地址).(地址寄存器的内容).

For returning the first half (address) of the cons cell. (Contents of address register).

cdr

用于返回 cons 单元格的后半部分(递减).(递减寄存器的内容).

For returning the second half (decrement) of the cons cell. (Contents of decrement register).

缺点

用于制作新的 cons 单元格,地址一半包含 cons 的第一个参数,减量一半包含第二个参数.

For making a new cons cell, with the address half containing the first argument to cons, and the decrement half containing the second argument.

结合起来:S-Functions

然后他继续添加到他的基本符号中,以便能够编写他所谓的 S-functions:

Tying it together: S-Functions

He then went on to add to his basic notation, to enable writing what he called S-functions:

  1. 引用

表示一个表达式而不求值.

To represent an expression without evaluating it.

cond

与前面描述的谓词一起使用的基本条件.

The basic conditional to be used with the previously described predicates.

lambda

表示一个函数.

标签

虽然他不需要递归,但他可能不知道Y-Combinator(根据 Paul Graham 的说法),他补充道这样做是为了方便并实现简单的递归.

Though he didn't need this for recursion, he might not have known about the Y-Combinator (according to Paul Graham), he added this for convenience and to enable easy recursion.


所以你可以看到他实际上定义了 9 个基本的操作符"为他的 Lisp 机器.在之前对另一个问题的回答中,我解释了如何用这个系统表示和操作数字.

但是这个问题的答案实际上取决于你想从你的 Lisp 机器上得到什么.你可以在没有 label 函数的情况下实现一个,因为你可以简单地在功能上组合一切,并通过应用 Y-Combinator 获得递归.

But the answer to this question really depends on what you want out of your Lisp machine. You could implement one without the label function, as you could simply functionally compose everything, and obtain recursion through applying the Y-Combinator.

atom 可能会被丢弃.

本质上,您可以拥有带有这 9 个已定义原语中的 7 个的 McCarthy 的 LISP 机器,但您可以表面上定义一个更简洁的版本,具体取决于您希望给自己带来多少不便.我非常喜欢他的机器,或者像 Clojure 这样的新语言中的许多原语.

You could essentially have McCarthy's LISP machine with 7 of these 9 defined primitives, but you could ostensibly define a more concise version depending on how much inconvenience you'd want to inflict on yourself. I like his machine quite fine, or the many primitives in the newer languages like Clojure.

这篇关于构建 LISP 机器需要多少个原语?十个、七个还是五个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆