by Jensson · 4y ago · 0 comments
Like this:
(+ (EXPT 23 2.4)
(SIN (* 44 0.23 22))
(COS (+ 12 0.43 19.0))
(TAN (/ 1.4 0.77 3/4))
)
Instead of (+ (EXPT 23 2.4)
(SIN (* 44 0.23 22))
(COS (+ 12 0.43 19.0))
(TAN (/ 1.4 0.77 3/4))) ((paris (french))
(los-angeles (english spanish))
)
Something like above would be used if one often adds data clauses to that expression.Also when there are comments on the last line, then sometimes the expression might be closed on the following like:
((paris (french)) ; city 1
(los-angeles (english spanish)) ; city 2
)If the opening bracket is on the same line as content, then so is the closing bracket.
By this rule, we have two options:
(+
(EXPT 23 2.4)
(SIN (\* 44 0.23 22))
(COS (+ 12 0.43 19.0))
(TAN (/ 1.4 0.77 3/4))
)
or (+ (EXPT 23 2.4)
(SIN (\* 44 0.23 22))
(COS (+ 12 0.43 19.0))
(TAN (/ 1.4 0.77 3/4)))
The first option has both opening and closing brackets on their own lines, while the second has neither. Note that I consider the function name to be part of the opening bracket since it's distinct from the parameters.This is consistent with other languages:
[1, 2, 3]
f(x, y, z)
[
1,
2,
3,
]
f(
x,
y,
z
)
instead of [1,
2,
3,
]
f(x,
y,
z,
) [ x
, y
, z
]
which looked really weird to me first but I’ve found it to improve legibility a lot. (Of course there’s a reason it’s idiomatic in Haskell and not elsewhere.)That the expression is ended I can see in the typical Lisp expression because of the block structure. The single parentheses does make the layout very cluttered and visually ugly. It gets even worse in typically larger Lisp code or data.