mozilla/rust — pull request #6333 by bjz (2013-05-08 15:49:23+00:00)
Title: Add Scheme-style `cond!` macro to syntax::ext::expand

Addressing issue #6037, this Scheme-style conditional helps to improve code clarity in instances where the `if`, `else if`, and `else` keywords obscure predicates undesirably.

Here is an example:

~~~rust
let clamped =
if x > mx { mx }
else if x < mn { mn }
else { x };
~~~

Using `cond!`, the above could be written as:

~~~rust
let clamped = cond!(
| x > mx { mx }
| x < mn { mn }
_ { x }
);
~~~

The optional default case is denoted by `_`.

I have altered `std::fun_treemap` to demonstrate it in use. I am definitely interested in using it for some of the numeric functions, but I will have to wait for it to reach `stage0` first.