Code · 1 file
Sample D File
D with structs, ranges and templates. Every language sample implements the same small program so you can compare them side by side.
D · 553 B
Sample D file
An idiomatic D example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.
CC0 · free for any use · Verified by an independent tool · Report a problem
// Sample D program — samplefiles.com
import std.algorithm : map, sum;
import std.stdio : writefln;
struct Customer
{
int id;
string name;
double balance;
bool isVip() const { return balance >= 10_000; }
}
void main()
{
auto customers = [
Customer(1, "Ada", 12_500),
Customer(2, "Grace", 830.5),
Customer(3, "Linus", 10_000),
];
foreach (c; customers)
writefln("%-6s %10.2f %s", c.name, c.balance, c.isVip ? "VIP" : "");
writefln("Total: %.2f", customers.map!(c => c.balance).sum);
}File details
Download from the command line
curl -L -o sample.d https://files.samplefiles.com/code/d/sample.dwget https://files.samplefiles.com/code/d/sample.dhttps://files.samplefiles.com/code/d/sample.dprintf '%s %s\n' 9dbc5040887c9f7583506012c2d6b4f09531ee7eee32c9c03caff6a205d3a888 sample.d | shasum -a 256 -cOr check the download in your browser with the checksum calculator.