Use parentheses for cond! macro instead of preceding pipes
This is temporary. Once the macro parser has improved or been re-written these can be removed.
This commit is contained in:
parent
b9824e18c2
commit
7e4a176dd3
@ -37,8 +37,8 @@ pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap
|
||||
@match m {
|
||||
@Empty => Node(@k, @v, @Empty, @Empty),
|
||||
@Node(@copy kk, vv, left, right) => cond!(
|
||||
| k < kk { Node(@kk, vv, insert(left, k, v), right) }
|
||||
| k == kk { Node(@kk, @v, left, right) }
|
||||
(k < kk) { Node(@kk, vv, insert(left, k, v), right) }
|
||||
(k == kk) { Node(@kk, @v, left, right) }
|
||||
_ { Node(@kk, vv, left, insert(right, k, v)) }
|
||||
)
|
||||
}
|
||||
@ -49,8 +49,8 @@ pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
|
||||
match *m {
|
||||
Empty => None,
|
||||
Node(@ref kk, @copy v, left, right) => cond!(
|
||||
| k == *kk { Some(v) }
|
||||
| k < *kk { find(left, k) }
|
||||
(k == *kk) { Some(v) }
|
||||
(k < *kk) { find(left, k) }
|
||||
_ { find(right, k) }
|
||||
)
|
||||
}
|
||||
|
@ -559,8 +559,8 @@ pub fn core_macros() -> ~str {
|
||||
//
|
||||
// ~~~
|
||||
// let clamped = cond!(
|
||||
// | x > mx { mx }
|
||||
// | x < mn { mn }
|
||||
// (x > mx) { mx }
|
||||
// (x < mn) { mn }
|
||||
// _ { x }
|
||||
// );
|
||||
// ~~~
|
||||
@ -568,12 +568,12 @@ pub fn core_macros() -> ~str {
|
||||
// The optional default case is denoted by `_`.
|
||||
//
|
||||
macro_rules! cond (
|
||||
($( | $pred:expr $body:block)+ _ $default:block ) => (
|
||||
( $(($pred:expr) $body:block)+ _ $default:block ) => (
|
||||
$(if $pred $body else)+
|
||||
$default
|
||||
);
|
||||
// for if the default case was ommitted
|
||||
( $( | $pred:expr $body:block )+ ) => (
|
||||
( $(($pred:expr) $body:block)+ ) => (
|
||||
$(if $pred $body)else+
|
||||
);
|
||||
)
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T {
|
||||
cond!(
|
||||
| x > mx { return mx; }
|
||||
| x < mn { return mn; }
|
||||
(x > mx) { return mx; }
|
||||
(x < mn) { return mn; }
|
||||
)
|
||||
return x;
|
||||
}
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
fn clamp<T:Copy + Ord + Signed>(x: T, mn: T, mx: T) -> T {
|
||||
cond!(
|
||||
| x > mx { mx }
|
||||
| x < mn { mn }
|
||||
(x > mx) { mx }
|
||||
(x < mn) { mn }
|
||||
_ { x }
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user