On Monday, 8 April 2019 at 19:29:33 UTC, 4544fa8d wrote:
It's really not possible to call functions in modules like in
any other languages? :S
What some other languages do is collect all of those calls into an
implicit function that's called before main(). What D does is run
that code at compile-time. Silly example:
import std.stdio;
T twice(T)(T n) { return 2 * n; }
auto x = twice(5);
void main() {
writeln(x);
}
Take a look at the compiled result: https://godbolt.org/z/8vLsv9
There's a twice() that's compiled in, but if you look at x it's
already the result of a call to twice():
int example.x:
.long 10
and the (unoptimized) main just fetches that number to print.