5 ms·
Stopping at the syntax when talking about Lisp is pretty narrow-minded and completely misses what makes Lisp so great. It's like saying to a car driver that mot
by Monkeyget 12y ago
Stopping at the syntax when talking about Lisp is pretty narrow-minded and completely misses what makes Lisp so great. It's like saying to a car driver that motorcycles are nice because they only have two wheels and thus take less parking space. Technically true but not what makes them exciting. When you describe to the coffee-drinking radio-listening commuter about taking corners and being one with the road he won't understand what the point is. But if he were to drive a bike around a circuit, oh boy!
I'm probably going to fail miserably but let me attempt to explain cornering and being one with the road in Lisp.
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:
(list 1 (list 2 3))
(+ 1 (+ 2 3))
Another example :
(task
(time 14 00)
(log "beginning of task")
(job (backup-files (important-files-in (list-files))))
(job (delete (list-files))))
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 :
(define-function (name add) (parameters a b)
(body (return (+ a b))))
If we simplify things a bit we end up with :
(defun add (a b)
(+ a b))
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 :
//not actual lisp code but you get the point
var my-task = (task
(time 14 00)
(log "beginning of" )
(job (backup-files (important-files-in (list-files))))
(job (delete (list-files))))
my-task is now a list containing sub lists representing a task.
What if we did this now :
//not actual lisp code
(defun time (hour minutes) (print "%d:%d" hour minutes))
(defun log (string) (print string))
//we say that task is a function
//that should call each list it contains as a function
(defun task () /*execute each list it contains*/)
//...
Now we can just do:
(my-task)
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
- evanspa 12y agoNice comment. Very reminiscent of PG's "Beating the Averages" essay: http://www.paulgraham.com/avg.html 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).
- Denzel 12y agoFor 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.
- Jach 12y agoFor 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 https://news.ycombinator.com/item?id=7423626