Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created May 22, 2014 03:13
Show Gist options
  • Save bstrie/a53d2e51910c5addb63a to your computer and use it in GitHub Desktop.
Save bstrie/a53d2e51910c5addb63a to your computer and use it in GitHub Desktop.
#![feature(macro_rules)]
macro_rules! foo {
($id:expr, $head:expr, $($tail:expr),+) => ({
foo!($id, $head);
foo!($id+1, $($tail),+);
});
($id:expr, $var:expr) => ({
println!(" {} = {},", $var, $id);
});
}
macro_rules! bar {
($name:expr, $start:expr, ($($args:expr),+)) => ({
println!("enum {} \\{", $name);
foo!($start, $($args),*);
println!("\\}");
});
}
fn main() {
bar!("Qux", 8, ("Q1", "Q2", "Q3"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment