-
Notifications
You must be signed in to change notification settings - Fork 8
Description
fmt
currently puts an if
expression onto one line as long as it will fit in the column limit. However, this can make it tricky to tell where the true branch ends and the false branch begins. See these GitHub threads:
- Automated Resyntax fixes racket/scribble#441 (comment)
- Automated Resyntax fixes racket/drracket#681 (comment)
- Automated Resyntax fixes racket/drracket#678 (comment)
The if
expressions in those threads are:
(if subs (list (restore expr (loop subs))) (list (shift expr)))
(if (< s 0) (loop (+ s (* 2 pi))) s)
(if (boolean? mred-launcher) (if mred-launcher 'mred 'mzscheme) #t)
I agree with Robby that these are pretty difficult to read. After some discussion in the Racket Discord server, I have a fmt
proposal: if
expressions should only occupy a single line if the true branch and false branch don't have parentheses. The three examples above would be formatted according to that rule like this:
(if subs
(list (restore expr (loop subs)))
(list (shift expr)))
(if (< s 0)
(loop (+ s (* 2 pi)))
s)
(if (boolean? mred-launcher)
(if mred-launcher 'mred 'mzscheme)
#t)
However, these if
expressions would still be allowed to occupy a single line:
(if simple? widget gizmo)
(if (foo? x) x #false)
(if (f (g (h a b c))) 'good 'bad)
This seems to make it easy to tell which expressions are the true and false branches without overly penalizing simple if
expressions.