Reputation: 4713
When I'm learning Clojure of some languages, the readability and convenience of syntax is the most important issue(Maybe this's wrong..).
So, Clojure is greatly appealing me, but there might be to many brackets to maintain.
And I'm considering if there's a script with which I can write code without some brackets and then compile it to Clojure, that should be better. Does such programe exists so far?
(Once told there is a indentation syntax for Scheme, that's nice. How about Clojure?)
Upvotes: 3
Views: 248
Reputation: 824
Once you get used to the parens, they actually become easier to read than Java code. What's more critical for readability is proper indentation. Any decent IDE will correct the indentation of a block of code for you.
However, you might find that macros do what you want. For example, the threading macro (->) or the .. macro. And you can write your own macros for more specific purposes.
Here's an example:
user=> (str (inc (Integer/parseInt "10"))) "11"
could be rewritten as user=> (-> "10" Integer/parseInt inc str) "11"
A savings of two paren-pairs! Woot!
Going back to your original question, if you can write non-ambiguous code with fewer parens for a given situation, then it should be possible to write a macro to expand the less-parens syntax into real Clojure. Do you have an example of what you're looking for?
Upvotes: 3
Reputation: 106351
Usually you use an editor or IDE that will take care of the brackets for you.
It is especially useful to have "rainbow parens", i.e. the parentheses are given different colours to match their nesting level so you can quickly see how they line up.
Some options:
Note that in general, because of it's conciseness, Clojure code uses fewer parentheses than the equivalent Java code.
Upvotes: 8