March 30, 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
March 31, 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??

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)

April 05, 2022
On Wednesday, 30 March 2022 at 20:05:07 UTC, H. S. Teoh wrote:

>
> 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

That's the way to think about it. Thanks! )
April 05, 2022

On Thursday, 31 March 2022 at 03:44:30 UTC, Tejas wrote:

>

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

Or something like this https://en.wikipedia.org/wiki/Partial_evaluation

April 05, 2022

On Friday, 25 March 2022 at 20:07:39 UTC, Anonymous wrote:

>

Input:

void main()
{
    import std.stdio : writeln;
    writeln("Hello, World!\n");
    //I'm not sure if the ^^ is necessary or not
}

Not efficient enough. :^)

extern (C) { int write(int, immutable char*, int); }

void main()
{
	write(1,&"Hello, world!\n"[0],14);
}
1 2 3 4
Next ›   Last »