Hello, World!

Tejas notrealemail at gmail.com
Thu Mar 31 03:44:30 UTC 2022


On Wednesday, 30 March 2022 at 18:50:40 UTC, Max Samukha wrote:
> On Wednesday, 30 March 2022 at 15:49:08 UTC, H. S. Teoh wrote:
>
>>
>> And pragma(msg) is technically not your program outputting the 
>> message,
>> but the compiler. You need to put it in main() for a proper
>> implementation of Hello World. ;-)
>>
>>
>> T
>
> template add(int x)
> {
>     pragma(msg, x);
>     int add(int y)
>     {
>         import std.stdio: writeln;
>         writeln(y);
>         return x + y;
>     }
> }
>
> void main()
> {
>     auto z = add!1(2);
> }
>
> Is this a program that starts at compile time and continues at 
> run time, or a meta-program that generates another program? )

It's a normal template... what are you talking about??

```d
1
2
3
import object;
template add(int x)
{
	pragma (msg, x);
	int add(int y)
	{
		return x + y;
	}
}
extern (C) extern (C) void main()
{
	add(2);
	add(1);
	add(0);
	return 0;
}
add!1
{
	pure nothrow @nogc @safe int add(int y)
	{
		return 1 + y;
	}

}
add!2
{
	pure nothrow @nogc @safe int add(int y)
	{
		return 2 + y;
	}

}
add!3
{
	pure nothrow @nogc @safe int add(int y)
	{
		return 3 + y;
	}

}
```
(Took the output from the "AST" option in run.dlang.io)
(Used `-betterC` to strip away boilerplate stuff)


More information about the Digitalmars-d mailing list