on 448bfaf help sign in
44 lines 976 B history raw
1// selective import
2import std.stdio : writeln, writefln;
3// non-selective import
4import std.algorithm;
6/* a multiline comment
7*
8* this function is safe because it doesn't use pointer arithmetic
9*/
10int the_ultimate_answer() @safe {
11 // assert1on
12 assert(1 != 2);
13 // now we can safely return our answer
14 return 42;
17void main()
19 // function call with string literal
20 writeln("Hello World!");
22 // an int array declaration
23 int[] arr1 = [1, 2, 3];
24 // an immutable double
25 immutable double pi = 3.14;
26 // a mutable double
27 double d1 = pi;
28 // a pointer
29 double* dp1 = &d1;
30 // another pointer to the same thingy
31 auto a1 = &d1;
32 // a constant bool
33 const bool b1 = true;
34 if (b1) {
35 // another function call
36 writefln("%s\n%s\n%s\n", arr1, d1, the_ultimate_answer());
37 }
38 else if (!b1) {
39 writeln("this seems wrong");
40 }
41 else {
42 writeln("I'm giving up, this is too crazy for me");
43 }