For the past few months I've been studying Lisp, reading SICP, and just trying to become more familiar with the concepts. Like many people, I was put off by Lisp's seemingly arcane syntax, which now feels beautiful to me. I can't fully explain it, but for years I had been searching for a way to reduce and abstract duplication in the structure of my code. (There's a fundamental difference between this, and simply pulling something out into a function or method.) It wasn't until I came across a great explanation of homoiconicity and macros that I became "enlightened." Lisp was what I was looking for all along.
One day, I tried explaining it to my manager, and he just couldn't get it. It wasn't clicking. Until I showed him a demo of symbolic differentiation (a la SICP), at which point he said, "Holy shit," and sat there for a few minutes considering all the implications. That was one of the greatest moments we ever shared together.
For those who aren't so lucky to have an understanding manager (though you didn't say your manager then agreed to let you start writing everything in a lisp...), I just wanted to bring out the punchline of this hilarious and melancholy comment[1] from a couple months ago: "And yet: the money guys are offering money. Just swallow your pride, play 'Stairway to Heaven' at the wedding, and pretend you've never had crazy eyes when talking about homoiconicity, and the rent will be paid."
[1] Don't upvote me: https://news.ycombinator.com/item?id=7423626
Nice comment. Very reminiscent of PG's "Beating the Averages" essay:
http://www.paulgraham.com/avg.html
Paul's essay was the catalyst that got me to (re-)discover Lisp for myself. Scheme was taught in my CompSci I course a long time ago; but at the time, it was just a weird looking language that I forgot (CS II and beyond was all in C++ at my college).
What's so great about Lisp? : its extreme malleability in the way you write code and the data it uses.
Code and data are the exact same things in lisp. They are represented the same way : lists represented with braces around them who can be nested. It's called s-expressions and they are in the form (<operator> <operand1> <operand2> <operand3>). There is no fundamental difference between code and data they are just list represented as s-expressions:
Another example : Quick, what's that above, code or data? How about both?The one nice thing about s-expressions (sexp) instead of classical curly braces is that the code written in sexp IS ITSELF the abstract syntax tree of that code.
For example, think of a function function add(a, b){return a+b;}
You could convert this function into its syntax tree like this :
If we simplify things a bit we end up with : Lo and behold, the example above IS Lisp code. Is that code or data? How about both?The syntax of Lisp is the same as its internal represention. That's called homoiconicity.
What's so great about that? Well, mix that with macros whose language is Lisp itself and can do anything with s-expressions and you end up wielding great powers.
A simple example. Let's go back to our task example. We can treat it as data :
my-task is now a list containing sub lists representing a task. What if we did this now : Now we can just do: What do you think is going to happen? Yes, the data, the task is being executed.Now for the last touch : add to Lisp a powerful macro system that can take any s-expression (any list) and transform it any way it see fits and you end up yielding great power. What's that language? It's Lisp itself. Code is data. Lisp code evaluting other lisp code. I am so enlightened.
Not enlightened? Didn't get anything out of my post? Then give Lisp a try! You have to dive into Lisp to be able to get it. As Eric raymond put it : "Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot." - ESR