What type functions mean on a language level
Jacob Carlborg
doob at me.com
Wed Jan 6 13:20:35 UTC 2021
On 2021-01-02 10:28, Stefan Koch wrote:
> The issue here is knowing when the type is complete.
> Imagine you did not put int into there, but some template or another
> typefunction result.
> At which point can I take the lock and register myself in the type
> universe?
> And how do I make sure I don't have to type LinkedList(f(x, g(y), j(z)))
> to reference the type?
>
> I guess I could create the name to just be "LinkedList(f(x, g(y),
> j(z)))" where f(x, g(y), j(z))) is eagerly evaluated, and then the name
> is LinkedList(float) or something like that.
>
> But that seems like reinventing templates with all their troubles...
I don't know. I'm not the expert.
> perhaps it's still worthwhile though?
I like the syntax at least :)
Your example doesn't have the same problem because it's explicitly
calling `__internal__magic__registerType`?
> Hmm I wanted to avoid having to puzzle ast nodes together, as I find it
> rather counter verbose to use.
> simple stuff like;
> mixin(f(a, b));
> becomes
> new CallExp(findFunction("f"), [findVariableExpression("a"),
> findVariableExpression("b")].insertIntoTreeInPlace();
There's nothing that prevents building helper functions on top of the
low level AST.
In my idea for AST macros, there would be support for quasi-quoting and
splicing. It's implemented as a built-in function that converts the
internal AST (defined in the compiler) to the external AST (defined in
druntime).
ast(f(a, b)); // single line
ast({ // multiple statements
int a = 3;
int b = 4;
f(a, b);
});
auto name = ast(a);
ast({
int $name = 3; // splicing. This will declare a variable with the
name "a"
});
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list