사용 목적 :Lispian cond 매크로를 구현하는 방법은 무엇입니까?
cond! {
x > 5 => 0,
x < 3 => 1,
true => -1
}
가 확대 될 전망이다 : 그것은 포괄 else { ... }
접미사를 생성하지 않는다는
if x > 5 { 0 } else if x < 3 { 1 } else if true { -1 }
참고.
내 시도 :
macro_rules! cond(
($pred:expr => $body:expr) => {{
if $pred {$body}
}};
($pred:expr => $body:expr, $($preds:expr => $bodies:expr),+) => {{
cond! { $pred => $body } else cond! { $($preds => $bodies),+ }
}};
);
그러나, 컴파일러는 else
키워드에 대해 불평.
error: expected expression, found keyword `else`
--> src/main.rs:32:34
|
32 | cond! { $pred => $body } else cond! { $($preds => $bodies),+ }
| ^^^^
설명해 주셔서 감사합니다. –