-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"if .. then .. else" is formatted inconsistently #495
Comments
I like the OCaml'y style of: if blah
then bloop
else bleep Unless used as a kind of early out or so then this common: if not blah then bloop else
...more stuff... |
@OvermindDL1 I am in two minds on this, // Format 1
if x
then
let y = 1
y
else
let y = 1
y
// Format 2
if x then
let y = 1
y
else
let y = 1
y |
When the branches are complex then in OCaml I've always done: if x then
let y = 1 in
y
else
let y = 2 in
y So the Format 2 in your example. /me really dislikes whitespace or newline sensitivity as a side note... |
I have been bitten enough by indentation based syntax to prefer non-whitespace sensitivity but there are some unfortunate ambiguities that would need resolving to let that happen. (* Fails since the last alternative is associated with the inner match *)
let x = match 1 with
| 2 ->
match () with
| _ -> 1
| _ -> 0 (* Syntax error *)
let x =
let y = "a"
y
print_string x;;
(* Add `in` to make it work *)
let x =
let y = "a"
in
y
in
print_string x;; Perhaps there is a a better syntax that would resolve these cases though 🤔 |
Well the OCaml usual way for those are: let x = match 1 with
| 2 ->
begin match () with
| _ -> 1
end
| _ -> 0 Also do not that the OCaml community-standard formatter/indenter As for the let _ =
let x =
let y = "a" in
y in
print_string x For note, Also, I'd definitely recommend building a formatter into this system as well, being able to have the compiler output formatted source is a massive boon! |
Like https://github.com/gluon-lang/gluon/tree/master/format ? 😎
Tools or convenention can make it clear when one is doing it wrong. I don't like the idea of needing to help someone new with an issue and having the answer be "you should follow convention X or use tool Y".
It works ok in simple examples like this but since gluon has no concept of a top-level all the |
Whoo!
Exactly why it should be baked into the compiler. The compiler could also help along by having a default enabled warning/error of when a match is used directly in the case of another match without an enclosing scope too.
I personally still wouldn't mind it but eh. :-)
Still exceptionally dislike whitespace sensitivity... ^.^; |
For context this is the diff of the prelude after the syntax became whitespace sensitive dc78cf8#diff-0ff65e307e9232ed9edea0d444dd1f83
Perhaps. Needing to wrap parentheses around match is so ugly though :( May need to change the syntax a bit in that case. Rust works fine with |
I'd be good with |
The auto formatting of https://github.com/gluon-lang/gluon#24 is inconsistent.
The text was updated successfully, but these errors were encountered: