evehal
October 4, 2019, 11:55am
1
macro_rules! recurrence {
( a[n]: $sty:ty = $($inits:expr),+ ... $recur:expr ) => {
/* ... */
};
}
fn main() {
let fib = recurrence![a[n]: u64 = 0, 1 ... a[n-1] + a[n-2]];
for e in fib.take(10) { println!("{}", e) }
}
im learning macro tutorial:
https://danielkeep.github.io/quick-intro-to-macros.html
can not compile this macro,please help
sinkuu
October 4, 2019, 1:39pm
2
Hey, look at the note in the begenning of page:)
Note : This article is for an obsolete version of Rust, and has been superceded by the slightly less misleadingly named "A Practical Intro to Macros in Rust 1.0" .
1 Like
ExpHP
October 4, 2019, 1:48pm
3
It won't compile because the body of the macro was left out. See the /* ... */
?
evehal
October 4, 2019, 2:02pm
4
thank you
i tried https://danielkeep.github.io/practical-intro-to-macros.html,still not work.
$seq:ident [ $ind:ident ]: $sty:ty = $($inits:expr),+ ... $recur:expr
^^^not allowed after 'expr' fragments
ExpHP
October 4, 2019, 2:16pm
5
I assume the error is pointing at the ...
? That would make sense, because the guide appears to have been written before macro_rules was stabilized, and the future-proofing rules (that forbid e.g. ...
after expr
) were added in the same 1.0.0-alpha release.
So yes, it is because the guide is old. Here is the new version:
https://danielkeep.github.io/tlborm/book/pim-README.html
evehal
October 5, 2019, 12:18am
6
according to https://github.com/rust-lang/rust/issues/25658
... is the problem,but i dont know how to fix it
Simply put, you can't fix something that's there for macro hygiene. You'll have to work around it.
Something that would work similarly with a delimiter :
macro_rules! recurrence {
(a[n]: $sty:ty = ($($inits:expr),+) ... $recur:expr) => {
/**/
};
}
evehal
October 5, 2019, 5:43am
8
macro_rules! recurrence {
(a[n]: $sty:ty = ($($inits:expr),+) ... $recur:expr) => {
/**/
};
}
fn main() {
recurrence![ a[n]: u64 = (0, 1) ... a[n-1] + a[n-2] ];
}
it works,but not natural:
a[n]: u64 = 0, 1 ... a[n-1] + a[n-2]
system
Closed
January 3, 2020, 5:43am
9
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.