Complete these tasks to reinforce what you learned in this module.
Define a macro double! that takes one expression and expands to that expression added to itself (e.g. double!(5) becomes 5 + 5). In main, print the result of double!(10).
$e:expr in the pattern and $e in the expansion.// Task 1: double! macro. See tasks/TASKS.md.
fn main() {
todo!("macro_rules! double, print double!(10)");
}
Define a macro sum! that takes zero or more expressions separated by commas and expands to their sum. For example sum!(1, 2, 3) becomes 1 + 2 + 3. Use $( $e:expr ),* and repetition in the expansion: $( $e )+ with a single + between them (you can use a trick: expand to 0 $( + $e )*).
+ $e for each. Starting from 0 and adding each term gives the sum. The theory explains $( ... )*.// Task 2: sum! macro. See tasks/TASKS.md.
fn main() {
todo!("macro_rules! sum with repetition, print sum!(1,2,3,4)");
}