Hello, World!
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Mar 30 20:05:07 UTC 2022
On Wed, Mar 30, 2022 at 06:50:40PM +0000, Max Samukha via Digitalmars-d 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. ;-)
[...]
> 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 program with a split personality that prints half its output at
compile time and the other half at runtime. :-D
If you only compile but never run it, then you only get half of its
output, and if you run it multiple times you get redundant output. :-P
T
--
The two rules of success: 1. Don't tell everything you know. -- YHL
More information about the Digitalmars-d
mailing list