Home > Programming > Homoiconic – or code is data and data is code

Homoiconic – or code is data and data is code

If you are in software and if you haven’t heard this term before, chances are that you don’t know LISP, or you just have a cursory knowledge of this “mother of all computer languages”. Surely, I’ll prove why LISP is THE MOTHER OF ALL LANGUAGES –

Let’s take a look at the evolution of C# (and the features that were introduced in it at certain times or that are being introduced in it even now) –

Feature C# version Year of introduction
Predicates 2.0 2005
Closures 3.0 2008
Lambda Expressions 3.0 2008
Linq 3.0 2008
Lambda Statements 4.0 2010

And when did Lisp originate? As per Wikipedia – 1958 ๐Ÿ™‚ And in Lisp (or Clojure), everything is an s-expression, so any piece of code can be turned into data (or code as data)

Most certainly, if I show that C# borrows heavily from Lisp, doesn’t mean that every other language does; but C#, as a language (which was originally a Java clone) has come far ahead of Java, and I am sure Lisp is the super set of the most current mainstream languages (I’d love to be proven wrong).

So wouldn’t you like to drink directly from the (free) source (instead of a paid derivative) ๐Ÿ˜‰ But this post is not meant to be a war on which language is better right, so let’s move on…

The term homo-iconicity, means that code can be represented as data without having to resort to a different syntax (homo = same; iconic = appearance) –

So in Lisp (or Clojure) it is: (list 'GetPathsOfAllFiles folder file-filter)) [notice the tick "'" mark]

And in C#:ย  Func<int, int> twiceD = x => x * 2;
Expression<Func<int, int>> twiceE = x => x * 2;

The whole point is that when you use an Expression<> in C# code, that particular piece of code instead of being directly compiled in byte code and getting executed normally gets compiled into AST (abstract syntax tree) form, the advantage being that we can extract any information out of this AST.

This “extract any information” forms the basis of whole DSL magic using statically-typed languages like C#. This is the very same technique I used to achieve this – https://mmwaikar.wordpress.com/2010/01/24/wpf-magic-strings-and-some-linq-love/

For a deep dive into this whole homo-iconic fun, and other great C# stuff – please refer to the excellent blog post by Bart De Smet – http://bartdesmet.net/blogs/bart/archive/2009/12/29/more-linq-with-system-interactive-exploiting-the-code-data-relationship.aspx

So if Clojure becomes a hit in the .Net world (less likely), then I would love to work on it, else looks like I’ll have to move to JVM as a platform (of course with Clojure) ๐Ÿ™‚

Advertisements
Categories: Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: