gpt4 book ai didi

lisp - 想要区分值(value)和表达

转载 作者:太空宇宙 更新时间:2023-11-03 18:57:10 26 4
gpt4 key购买 nike

我想知道如何区分'value''expression'

In computer science, a value is an expression which cannot be evaluated any further (a normal form).[1] The members of a type are the values of that type.[1] For example, the expression 1 + 2 is not a value as it can be reduced to the expression 3. This expression cannot be reduced any further (and is a member of the type Nat) and therefore is a value.

我从下面的 url 中找到了上面的声明: https://en.wikipedia.org/wiki/Value_(computer_science) 2

从这句话中我觉得:

I think "value" look like the "atom" in chemistry based upon the definition of Mitchell, John C.

但有人否认了这一点:

But, even expressions can be (represented as) values. The classic case being an s-expression in Lisp-like languages. – user2864740

这个演讲在另一个线程中:what-is-the-value-in-1st-class-value 3

如果user2864740什么都不说,事​​情就这么简单了。但他这么说,我很困惑。

有人可以向我解释一下这种情况吗?还是类似 lisp 的语言中可能存在的差异?

提前致谢!

[1] 约翰·C·米切尔 (1996)。编程语言基础。麻省理工学院出版社。

最佳答案

如果您不了解 Lisp,请阅读 SICP玩一些Scheme实现。

(经典的 SICP 书籍是必读的 - 它是一本非常好的编程入门书籍 - 因此,即使您了解 Lisp 但没有读过 SICP,您也确实应该阅读它;而且它是免费提供的在线。)

我强烈推荐阅读 C.Queinnec 的 Lisp In Small Pieces这本书解释了 LISP 解释器或编译器表达式是如何设计的,因此涵盖您的问题非常详细。

(实际上你的问题需要一整本书来回答,Queinnec 的书就是那本书)

LISP 是一个 homoiconic语言,因此 s-expressions是值(但有几个值不是表达式,特别是 closures )。但大多数编程语言——C、Ocaml、Javascript、C++、Java 等——(遗憾的是)不是谐音:它们的 AST 不是一个值,表达式不能本地操作AST。

顺便说一句,维基百科的句子

a value is an expression which cannot be evaluated any further

并不总是正确的。例如,对于 C 语言,值和表达式是不同种类的野兽。

您还应该阅读有关 formal semantics 的内容的编程语言。

此外,阅读 Scott 的 Programming Language Pragmatics会给你一个更广阔的视野(通过几种编程语言)。

关于lisp - 想要区分值(value)和表达,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34647121/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com