macro
10 months ago in Rust
macro_rules! recurrence {
( a[n] = $($inits:expr),+ , ... , $recur:expr ) => {
/* ... */
};
}

fn main() {
let fib = recurrence![a[n] = 0, 1, ..., a[n-1] + a[n-2]];
for (i, e) in fib.enumerate().take(10) {
println!("{} {}", i, e)
}
}
/*
error: local ambiguity: multiple parsing options: built-in NTs expr ('inits') or 1 other option.
--> src/main.rs:8:40
|
8 | let fib = recurrence![a[n] = 0, 1, ..., a[n-1] + a[n-2]];
| ^^^
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19