David,

On the off-chance that you have not considered this, how about factoring the long if-else chain into a function that uses early returns, like:

fn (...) -> .. {
if (f()) {
  // ...
  ret;
}
if (g()) {
  // ...
  ret;
}
if (h()) {
  // ...
  ret;
}
// ...
}

I don't think it is a syntactically pretty as what you propose, but it does avoid adding a possibly rarely-used special case to the syntax.

Gareth

On 08/06/12 06:27, David Rajchenbach-Teller wrote:
        Dear Rusties,

   I am currently writing in C++ code that involves long strings of `if
... else if ... else if ... else if ...` and it dawns to me that we can
certainly sightly tweak the syntax of Rust to make such code much nicer.

Consider the following extract:

if (f()) {
   // ...
} else if (g()) {
  // ...
} else if (h()) {
  // ...
} else {
  // ...
}


_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to