4 ms·
If I understand correctly, homoiconicity isn't really about the symbols used in the source file to represent code are the same as the symbols used in the source
by AnimalMuppet 9y ago
If I understand correctly, homoiconicity isn't really about the symbols used in the source file to represent code are the same as the symbols used in the source file to represent data structures. It's really about the parse tree of the program using the same data structures that programs use for data, and therefore you can operate on the parse tree just the same as you can on regular program data.
- zmonx 9y agoTo distinguish homoiconic languages from others (where you may also "operate on the parse tree just the same as you can on regular program data"), a bit more qualification is needed though. For example, in typical cases, reasoning about such data structures (lists in Lisp, terms in Prolog, bytes in assembly code etc.) is very convenient in homoiconic languages, and in fact I think one could rightfully regard this ability to conveniently reason about a program's abstract syntax tree via built-in language mechanisms as a key advantage of homoiconic languages.
- icebraining 9y agoThe parse tree of Python uses the same data structures that programs use for data: objects. And you can definitively operate on them. Yet it's not homoiconic.
- benlorenzetti 9y agoThis is probably the raisin d'être of homoiconicity but it's more specific a concept than that. It's a conceptual property on the grammar of the language: there need to be control characters/words in the grammar like spaces and parentheses so that the parser can correctly generate nested lists, or trees matching the intended AST, even when it doesn't necessarily have full information about what the languages set of operative keyword are. Basically the parser has to support adding new, user defined operators. And then in addition to being able to parse user defined operators, then you have to have a decently organized, simple system for applying AST transformations and modifying tree objects. And there again homoconicity in the grammar can be useful if it makes it easy to textually serialize and set object attributes.