3 ms·
The cases where hanging indentation is used are plain function calls. The places where the other kind of indentation is used are similar to control structures i
by hibbelig 6y ago
The cases where hanging indentation is used are plain function calls. The places where the other kind of indentation is used are similar to control structures in other languages. In C like languages you can tell by the curly braces that it’s a control structure (if, while,...). In Clojure they all use parentheses.
In Clojure you can define your own control structures, and the way to do that is using macros. That’s why the article talks about macros.
Does that help?
- ulrikrasmussen 6y agoYes, I think I understand that. The idea is to make a visual distinction between a function call and a macro invocation, as the latter is used as a mechanism to provide control structures that are usually built-in in Algol-like languages. I'm just not sure I actually understand how that distinction is supposed to be implemented by the "semantic indentation" style. The example in the article only shows how there is a difference between the styles for _function calls_ (calls to `filter`). But I suspect the example is just a bad one for illustrating the authors point. In general though, I think hanging indentation is a bad idea for the reasons I stated above :).
- hibbelig 6y ago> I'm just not sure I actually understand how that distinction is supposed to be implemented by the "semantic indentation" style. Given an expression such as (foo bar baz), semantic indentation examines foo to determine whether it is a macro or a function, and produces two different indentations depending on the result. Fixed indentation always produces the same result, regardless of whether foo is a macro or not. The "semantic" in the name refers to the deeper analysis required: If you see a "defmacro" somewhere then you have to remember that it is a macro. (I think actually, it's a bit more complicated. Macros can have multiple arguments, and one is often special. Look at the control structure "when": it receives a condition and multiple "statements", and when the condition is true all statements are executed, in order. And semantic indentation knows this. So you get this: (when CONDITION STMT-1 STMT-2) But when you put the condition on an extra line, you get this: (when CONDITION STMT-1 STMT-2) Fixed indentation has no idea and produces the following hard-to-read thing instead: (when CONDITION STMT-1 STMT-2)
- ulrikrasmussen 6y agoThank you, this makes sense.