Concat_idents with something not an ident

I currently have a macro like this one:

macro_rules! modules {
    ($($n:ident,)*) => {
            mod $n;

I use it to create a lot of modules.

All the module identifiers begin with a p and then have a number.

Currently I have to write modules![p1, p2, p3,], but I'd prefer if I were able to just write the numbers and the macro were doing its magic to transform them, such that modules![1] were generating mod p1;.

I already found interpolate_idents, but it requires the distinct tokens to be valid identifiers already.

The seq-macro crate should be able to do what you want. It works on stable Rust as of 1.30.0.

seq!(N in 1..=3 {
    mod p#N;

// expands to:
mod p1;
mod p2;
mod p3;

Thank you, this helps.

The numbers I use are not a straight sequence but have some holes, but at least I can do it like this:

macro_rules! problems {
    ($($a:tt .. $b:tt,)*) => {

        $(seq!(N in $a..=$b {
            mod p#N;