How to throw args to macro?

macro_rules! c {
    ([$($r:expr),*]) => {
        $(println!("{:?}", $r);)*

fn main() {
    c!(["a", "b"]);    // it will print out "a", "b"
    //now I want to have ["a", "b"] in another var such as below:
    let mm = ["a", "b"];
    c!(mm);     // I want it print out "a","b" as above example, but it's not incorrect but i don't know how to write it?

Macros only have access to the literal tokens between the the opening and closing delimiters of the macro call. You can't expand a macro using the contents of mm, the macro will only see mm as an identifier.

You can use the identifier to generate code that will read the value at run time, but it doesn't sound like that's what you're trying to do.

I think I find the solution thanks to your insprision and suggestion, thanks so much,

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.