同形性究竟是什么意思?

发布于 2024-11-17 05:59:48 字数 214 浏览 4 评论 0原文

我试图理解 关于同像性的维基百科文章,但它太冗长了,没有简明地解释这个词背后的主要理论。我应该补充一点,我的母语不是英语,所以我更喜欢简单的英语而不是学术白皮书引用。

那么,如果一种语言是同形的,那么到底意味着什么呢?是什么让 C#、Java 或 JavaScript 成为非同象的?

I was trying to understand the Wikipedia article on homoiconity, but it's too verbose and does not explain the main theory behind the word concisely. I should add that I'm not a native English speaker so I prefer simple English over academic white paper quotes.

So, what exactly does it mean if a language is homoiconic? What makes C#, Java or JavaScript non-homoiconic?

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

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

发布评论

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

评论(3

喜你已久 2024-11-24 05:59:48

它的意思是“代码即数据”,这是 Lisp 家族的一般特征。

(add 2 3)

就像上面的字符串一样,它既是一个列表,也是一个函数调用。 “Homo”前缀代表了这一特征。

It means "code as data" which is a general characteristic of Lisp family.

(add 2 3)

Just like above string, which is both a list and also a function call. The "Homo" prefix stands for this characteristic.

一百个冬季 2024-11-24 05:59:48

Scheme 是同象的,因为它的程序具有数据结构的解释。

'(define (foo x) (* x x))

是一个列表,第一个元素是define,第二个(foo x)(列表),依此类推。引号 ' 的意思是:不要解释它,将其保留为列表。如果我们删除 ' 我们会得到

(define (foo x) (* x x))

一个Scheme 函数定义。因为Scheme程序定义是嵌套列表表达式(因此是一种“语法树文字”),并且Scheme是一种动态语言,所以您可以用它来构建非常强大的宏/代码生成系统。

现在,Java 不再是同构的,因为它不提供此类用于解析树片段的“程序文字”。当然,您可以定义一个

String helloWorld =
   "class Hello { public static void main(System.out.println(\"Hello, world!\"); }";

可以解析并提供给编译器的字符串,但这很尴尬,因为它是一个字符串而不是一个结构化术语。

Scheme is homo-iconic because its programs have an interpretation as data structures.

'(define (foo x) (* x x))

is a list, the first element of which is define, the second (foo x) (a list), and so on. The quote mark ' means: don't interpret this, leave it as a list. If we remove the ' we get

(define (foo x) (* x x))

which is a Scheme function definition. Because Scheme program definitions are nested list expressions (and thereby a sort of "syntax tree literals"), and Scheme is a dynamic language, you can play tricks with this to build very powerful macro/code generating systems.

Now Java isn't homo-iconic simply because it doesn't provide these kind of "program literals" that evaluate to parse tree fragments. Of course, you can define a string

String helloWorld =
   "class Hello { public static void main(System.out.println(\"Hello, world!\"); }";

which you could parse and feed to a compiler, but that's awkward, because it's a string rather than a structured term.

悸初 2024-11-24 05:59:48

同像对于不同的人来说可能意味着不同的事情。最初是这样定义的
在 TRAC 语言的上下文中,如下所示:

因为TRAC程序和文本在内部和内部具有相同的表示形式
在处理器之外,术语“homo-iconic”适用,来自“homo”含义
相同,图标含义表示。

然而,这个定义是有问题的,因为很难准确地确定
内部表示和外部表示是什么意思。这也根本不是什么
今天大多数人都是这么说的。

今天,大多数人的意思可能与公认的答案类似
作者:Mike Yang,即语言中结构化数据的表示
是优雅的(字面语法),并且这种数据结构本身就是主要手段
代表代码。

更令人困惑的是,这个概念通常被称为“代码即数据”(即
本身就是一个非常重载的术语)。

更多信息请参见:

Homoiconicy can mean different things to different people. Originally, it was defined
in the context of the language TRAC, as such:

Because TRAC procedures and text have the same representation inside and
outside the processor, the term homo-iconic is applicable, from homo meaning
the same, and icon meaning representation.

However, that definition is problematic, because it is hard to precisely pin down
what is meant by internal and external representations. It is also not at all what
most people mean by it today.

Today, most people probably mean something along the lines of the accepted answer
by Mike Yang here, namely that the represenation of structured data in the language
is elegant (literal syntax), and that such datastructures are themselves the main means
of representating code.

To confuse matters further, this concept is often called "code as data" (which
is itself a very overloaded term).

More info here:

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