Tutorial by Examples

import std.stdio; void main() { writeln("Hello World!"); } Multiple imports can either be specified in the same line, separated with a comma or in a new line. import std.stdio, std.math; import std.datetime; void main() { writeln("2^4: ", pow(2, 4)); writ...
Selective imports can help to cleanup the namespace and speed-up the compile-time even more, because the compiler only needs to parse the specific, selected functions. import std.stdio: writeln; void main() { writeln("Hello world"); }
You can also import symbols in any scope, the import will only be looked up when the scope is needed (i.e. compiled) and the imported names will only be exposed in the imported scope. Most commonly the scope for local imports are functions, structs and classes. void main() { import std.stdio:...
Modules can be exposed to other modules with public imports. public import std.math; // only exports the symbol 'pow' public import std.math : pow;
A local name for an import can be given, through which all references to the module's symbols must be qualified with: import io = std.stdio; void main() { io.writeln("Hello world"); std.stdio.writeln("hello!"); // error, std is undefined writeln("hello!&qu...
Selective imports may also be renamed. void main() { import std.stdio : fooln = writeln; fooln("Hello world"); }
Modules have a one-to-one correspondence with source files. The module name is, by default, the file name with the path and extension stripped off, and can be set explicitly with the module declaration. The ModuleDeclaration sets the name of the module and what package it belongs to. If absent, the...

Page 1 of 1