What exactly does homoiconicity mean?

女生的网名这么多〃 提交于 2019-12-03 01:32:06

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!