On Sunday, 8 June 2025 at 14:29:27 UTC, mitgedanken wrote:
I have following situation:
I have a struct ``Routine`` (base type) and its specializations
``!n``.
```d
struct Routine (uint argscount = 1) {
string name;
void delegate(inout Arguments!argscount) return call;
}
const auto ROUTINES = [
Routine!3(":input", toDelegate(&routine_input)),
Routine!2(":print", toDelegate(&routine_print)),
];
```
I understand why the given types are not compatible.
But not how I can store any base type regardless its
specialization.
I thought the code was self-explanatory. But I was wrong about
that. Whereby you are going in the right direction.
I have a ``struct`` "Argument".
```d
struct Argument (alias data) {
alias TData = typeof(Data);
TData data;
}
```
```d
struct Arguments (uint argcount, alias Data) {
Argument!Data[argcount] args;
}
// Is this struct needed? An alternative please.
```
And a ``struct`` "Routine".
```d
struct Routine(uint argcount, alias Data, alias ReturnValue) {
alias TRet = typeof(ReturnValue);
alias TArg = Argument!(Data);
alias Args = Argument!Data[argcount];
static if (argCount > 0) {
TRet delegate(TArg Args) call;
}
else {
TRet delegate() call;
}
}
```
I want to specify through these ``struct``s that a routine ...
A. returns the type ``TRet``
B. how many arguments (and their type*) it needs
**Background**
I write a simple programming language. For this I define routines
that can be called by the user. The routines are therefore
predefined. But they should be read by a ``const``. Of course I
could also build it into the parser/lexer, like everything else,
but that is not my problem.
Does this help?