Being a newbie to Lisp I'm wondering if the Lisp syntax could be "fixed"?
Some people say the syntax in Lisp is one of its biggest strengths. I don't quite understand this.
Isn't it possible to replace "obvious" parentheses with a combination of white spaces, new lines and indenting? Just like in Python?
It looks to me like parentheses are the most used characters in Lisp code. I'm wondering if that's true - but if it is, isn't this a suggestion, that there is some redundancy in the syntax?
Is there some simple answer to the question - why so many parentheses?
For example:
(defun factorial (x)
(if (= x 0)
1
(* x
(factorial (- x 1)))))
Why not:
defun factorial (x)
if (= x 0)
1
* x
factorial
- x 1
e.g. close parentheses at the end of line, and always open them on new lines. Only the 1 would be ambiguous - is it 1 or (1) - but we could introduce an exception - single tokens are not "listified".
Could this work?
Edit:
Thank you all! I see now there are some links at the lispin site.
There is an alternate Racket Syntax.
reads as
It could work. It's called Dylan.
Even Paul Graham, a vocal advocate for the Lisp family of languages, has removed some parentheses from his own dialect Arc:
(from the Arc Tutorial)
Several times I've compared Lisp code and equivalent code in other languages. Lisp code has more parens, but if you count all grouping characters []{}() in other languages, Lisp has fewer parens than all these. It's not more verbose: it's more consistent!
When seen from this point of view, the "problem" is simply that Lisp uses one type of construct (lists) for everything. And this is the basis for its macros, its object system, a couple of its most powerful looping constructs, and so on. What you see as a minor style issue (would brackets look cooler? probably) is actually a sign of language power.
That said, Lisp is all about giving power to the programmer. If you want, write your own dialect that lets you do this. Lisp (unlike some languages I could mention!) is all about programmer power, so use it. If you can make it work, maybe it'll take off. I don't think it will, but there's nothing to stop you from trying, and you'll learn a lot either way.
You'll change your mind once you write a couple of macros.
It's been done lots of times (a < twenty line preprocessor will do wonders). But there is also an advantage to having them explicit. It drives home the parallelism between code and data, and in a way leads you out of the sort of thinking that makes you find them annoying.
You could (for an analogous example) take an object oriented language and remove all the syntactic grouping of methods into classes (so they became, in effect, overloaded functions). This would let you look at it more as you would a straight imperative language, but something would be lost as well.
When you look at lisp you're supposed to think "Everything is a list. Ommm"
(Well, Ok, the "Ommm" is optional).