Live data from Hacker News

Ask HN: Am I missing the Lisp magic?

news.ycombinator.com

1–10 of 12 posts

Ask HN: Am I missing the Lisp magic?

#1
I grew up coding in C and the many languages it inspired syntactically. I am currently learning some Erlang, which is cool. I for one can not understand the draw to Lisp or its syntax. It just looks confusing to me and in no way any easier than C to write/read. And looking at C-ish source code is effortless to get the right context but with stuff like )))))) ?? Someone explain please, also I understand some people like Lisp for some of its features, but are they tied to the syntax or can be easily copied over in another language? Also I know why functional programming so lets keep the discussion on the Syntax!

Re: Ask HN: Am I missing the Lisp magic?

#3
An important aspect of the "Lisp magic" is the language's homoiconicity[1].

Scheme, Clojure and other members of the Lisp-family share this language property, but it's not exclusive to lisps[2].

[1] http://en.wikipedia.org/wiki/Homoiconicity

[2] http://en.wikipedia.org/wiki/Homoiconicity#Examples

Re: Ask HN: Am I missing the Lisp magic?

#4
Another point is that when programming in a Lisp, it's highly recommended to use an editor/IDE that automatically handles the balancing of parentheses and provides keyboard shortcuts for common transformations of s-expressions.

For my day-to-day work with Clojure, Emacs and Paredit[1] meet that need handily.

[1] http://emacswiki.org/emacs/ParEdit

See also the Paredit CheatSheet: http://www.emacswiki.org/emacs/PareditCheatsheet

Re: Ask HN: Am I missing the Lisp magic?

#5
If you are looking at the ))))) you are looking at the wrong place. It's like placing your attention on the } } } } in C. Look at the opening parenthesis instead, and more importantly the indentation.

The benefit of S-expressions (lisp syntax) is that they make it easy to work with "code as data" instead of "code as text". This in turn makes it easy enough to generate code and define new forms of expression that people can actually do it without blowing the complexity budget.

Re: Ask HN: Am I missing the Lisp magic?

#6

If you are looking at the ))))) you are looking at the wrong place. It's like placing your attention on the } } } } in C. Look at the opening parenthesis instead, and more importantly the indentation . The benefit of S-expressions (lisp syntax) is that they make it easy to work with "code as data" instead of "code as text". This in turn makes it easy enough to generate code and define new forms of expression that peo…

How often is it important to treat code as data (in general) and would you say it makes things less complex than a C-like language?

Re: Ask HN: Am I missing the Lisp magic?

#7

If you are looking at the ))))) you are looking at the wrong place. It's like placing your attention on the } } } } in C. Look at the opening parenthesis instead, and more importantly the indentation . The benefit of S-expressions (lisp syntax) is that they make it easy to work with "code as data" instead of "code as text". This in turn makes it easy enough to generate code and define new forms of expression that peo…

How often is it important to treat code as data (in general) and would you say it makes things less complex than a C-like language?

You should use that a lot with lisp (or rather use it for projects that require you use it a lot). The secret sauce of lisp is that code is data.

Instead of using hacks like c's function pointers, lisp lets you pass code around as easily as any other variable type (1st class functions) instead of just pointers to the code. You can then exploit this ability to make code that will generate code on the fly and then execute it (macros). The homoiconicity of the language itself makes it much easier to make useful macros as opposed to just toy examples.

Since lisp and c are both turing complete, anything you can do in one language you can do in the other, but lisp's macros, 1st class functions, and homoiconicity make it possible to actually write something that would be almost impossible in c due to complexity issues. For example, in Cal's old intro cs course which used a lisp dialect, the last project of the course was writing a meta-compiler for the entire language. In contrast, Cal's compiler course uses c++ to compile only a small subset of python2 over an entire semester, and is considered one of the hardest classes due to the project's complexity.

Re: Ask HN: Am I missing the Lisp magic?

#8

If you are looking at the ))))) you are looking at the wrong place. It's like placing your attention on the } } } } in C. Look at the opening parenthesis instead, and more importantly the indentation . The benefit of S-expressions (lisp syntax) is that they make it easy to work with "code as data" instead of "code as text". This in turn makes it easy enough to generate code and define new forms of expression that peo…

How often is it important to treat code as data (in general) and would you say it makes things less complex than a C-like language?

Imagine unix/C without the ability to create new programming languages such as sh, python, yacc, etc. C would be all you had.

In lisp you can create sh, python, and C, and mix between them freely within a program/function/block with almost zero friction.

By having a simple universal syntax for all your sub-languages, syntax becomes a non-issue. What in unix may be separate language is just a library in lisp.

This is not a water-tight analogy but I hope it illustrates the point. If you want to really understand I recommend actually digging into a language in the lisp family such as Common Lisp, Racket or Clojure.

Re: Ask HN: Am I missing the Lisp magic?

#10

If you are looking at the ))))) you are looking at the wrong place. It's like placing your attention on the } } } } in C. Look at the opening parenthesis instead, and more importantly the indentation . The benefit of S-expressions (lisp syntax) is that they make it easy to work with "code as data" instead of "code as text". This in turn makes it easy enough to generate code and define new forms of expression that peo…

How often is it important to treat code as data (in general) and would you say it makes things less complex than a C-like language?

You will need the code as data feature for dealing with macros in a sane maner.
Post reply on HN