Michael Sokol

Software engineer's take on programing languages and paradigms. Talks about my open-source projects.
~ Sunday, November 27 ~
Permalink

On homoiconicity

Homoiconicity leverage metaprogramming for the languages that implement it. Why?

A homoiconic language is a language that treats code as a first-class citizen. Code is merely data expressed in a primitive data structure of the language that is manipulable like any other data-structure.

There’s no distinction between code and data, they both use the same data structure. Code can then be passed anywhere and manipulated by functions to return a different code. The resulting code can the be evaluated if necessary, or stored somewhere for later use.

In order to be homoiconic, a language needs to unify data and code under a common data structure. LISP chose lists. LISP’s lists can be used as a data representation format, or as code. Io, due to its object-oriented nature, chose ‘messages’ as the unifying structure.

But a language doesn’t need to be homoiconic to allow metaprogramming.

One of the draw-back I find in homoiconic language is also one of its strength. The code looks more like an abstract syntax tree than a technical report, or a book (like we like it so much when we use literate programing.)


 ()