Saturday, January 02, 2016

Javascript and Homoiconicity: Source-code that is a Data-Structure

Javascript and Homoiconicity: Source-code that is a Data-Structure

'' Homoiconicity is a feature of a language where the language’s “program code is represented as the language’s fundamental data type”...

Programming is the automation of process. We take real world processes and define them in algorithms that operate against data structures.

Data-structures and algorithms are cool. All the software we see today, and other abstractions like objects and functions, are built from these two abstractions: data-structures and algorithms.


Imagine then a program whose source-code is a data-structure in and of itself.


Homoiconic languages don’t need parameterized sub-routines.

If you are creating a language, and remove parameterized sub-routines as the core abstraction for communication of data between sub-routines, you end up with a Homoiconic language.

The fundamental datatypes (messages) take the place of parameterized sub-routines and passing of information between messages becomes an inherent part of the data-structure you create when programming.


Fundamental parts of the language are key words (loop, between, forEach, withEach, doWhile, etc.) but the structure of the code does not give any hint as to what those key words are.

var msgLoop = between {
  from: num(2),
  to: num(8),
  by: num(2)
  do: writeToCon({
    text: str("Hello world!")

msgLoop.go; // invoke the program
'' [source]

More info here.

I had a similar idea some years ago with a language I called "><self" (read Xself) which was an xml-ization of javascript's Json. The code would not be written as a sequence of instructions but as nested XML-like tags... I didn't know the name for this approach was Homoiconicity :)

No comments:

Post a Comment