Want internal macro macro facility
I think we may want a way to define at least local template sub-portions for repeated expansion.
${define THINGY { BLOMPLE ... } }
...
do the things
${call THINGY}
more things
${call THINGY}
Maybe at some point in the future we will want to do that cross-template. That seems like it would require some considerable thought, because the macros would all have to be expanded in the right order, with each of their expansions threaded through appropriately.
Even for local sub-portions, there are questions:
- Syntax for definition? Is that
${define }
right? Maybe we want a more specific word than "define". - Syntax for call. Dare we put these in the same namespace as template keywords? Is it OK to require a special introducer like
${call }
? Of course we might use$< >
or$[ ]
or something but that seems poor for this.$#
and$@
and so on aren't taken yet... - Will we want numbered arguments?
This is all going in the direction of a general macro language.
Motivation background
In playground/clonelike.rs
, we have:
where $( ${if fattr(getinternals::recurse) {
$ftype: GetInternals
} else {
$ftype: Clone
}
} +
) // [11a]
// [11a] I am getting tired of copy-pasting this over and over. Dare
// I ask for some way to get the regular macro facility to interact
// with these declarations?
I have found similar annoyance. It would be possible to ask the user to layer the two macro systems. I think there would be nothing stopping you doing:
macro_rules! define_getintrnals_with_getinternals {
{ { $($getinternals:tt)* } } => {
define_derive_adhoc! {
GetInternals =
...
impl GetInternals for $ttype
where $($getinternals)*
{
pub type Internals = [<$tname Internals>];
...
} }
define_getinternals_with_getinternals! {
{
$( ${if fattr(getinternals::recurse) {
$ftype: GetInternals
} else {
$ftype: Clone
}
} +
)
}
}
but this is horrific. We should have a built-in feature.