4 ms·
Wikipedia defines a homoiconic language as a language in which the primary representation of programs is also a data structure in a primitive type of the langu
by tgflynn 16y ago
Wikipedia defines a homoiconic language as a language
in which the primary representation of programs is also a data structure in a primitive type of the language itself
This definition doesn't seem quite right to me. It seems like it would apply to C because C source code is a string which is "a data structure in a primitive type of the language itself".
Wouldn't a better definition be "a language in which the source code and the corresponding abstract parse tree have identical representations" ?
- jules 16y agoThen Lisp wouldn't qualify. C arguably is homoiconic. It's just not a convenient representation.
- tgflynn 16y agoCare to explain your reasoning ? I thought this post was all about how Lisp meets that definition.
- jules 16y agoWell Lisp doesn't meet this definition: > "a language in which the source code and the corresponding abstract parse tree have identical representations" As the representation of code is still strings in Lisp, but the AST cons cells.
- tgflynn 16y agoOK: s/identical representations/identical external representations/
- jules 16y agoWhat do you mean by external representations?
- tgflynn 16y agoBy external representation I mean a representation of code and/or data that the programmer can see and/or interact with. With current technologies this almost always means some form of serialized text (an exception would be LabView where programs are represented through an interactive graphical environment). An internal representation is a representation of code and/or data that is processed internally by a computer but is not directly visible to the programmer. Example: Internal representation: (defun fact (n) (case n (1 1) (otherwise (* n (fact (- n 1)))))) External representation: The set of linked cons cells that the above list gets parsed into by a Lisp interpreter.
- tgflynn 16y agoI reversed internal and external in the above comment and for some reason am unable to edit it.
- jules 16y agoYou can only edit posts for a certain amount of time. Doesn't the requirement for homoiconicity become vacuous then? The definition was: > "a language in which the source code and the corresponding abstract parse tree have identical representations" Now is: > "a language in which the source code and the corresponding abstract parse tree have identical external representations" Where external representation of source code is defined as the representation that's used in the interpreter or compiler, that is, the abstract parse tree. So the definition becomes: "a language in which the abstract parse tree has the same representation as the abstract parse tree"? Alternatively replace "external" by "internal" everywhere in this post, if "internal" is the right name for CONS cells.
- tgflynn 16y agoNo the reversal in my above comments only applied to the example, not the way I defined internal vs. external representations. Sorry for the confusion. My point is that you can't tell by looking at the defun in my above comment whether you're looking at Lisp source code or the parse tree (represented as a nested list) for that source code. The same would not be true in C where the external representation of the parse tree would be the C syntax for initializing some set of nested struct's. That would look very different than the source code itself.
- lispm 16y agoC source code has not the external representation of a string.
- tgflynn 16y agoWhy because programs aren't quoted ?
- lispm 16y agoa string has a certain character level syntax: alphanumeric characters and escaped characters. Last I looked strings were part of the C syntax, but the C syntax was not based on strings. OTOH Lisp syntax is built on top of S-expressions, a data syntax.
- tgflynn 16y agoYes but I thank that is a rather minor point. I don't think people are usually thinking of character level syntax when they say that Lisp is homoiconic and C is not. Also it seems like it would be possible to define a variant of C that did use identical external representations for source code and strings. Such a language would still be essentially C and would be no (or at best only marginally) more homoiconic than is conventional C.
- lispm 16y agoSure you could define a variant of C. But C itself is how it is. C external source code is not defined on top of a data syntax. C also does not have any structured data representation for its source code and is not defined to work on that.