default.txt 880 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/rdmd
  2. // Computes average line length for standard input.
  3. import std.stdio;
  4. /+
  5. this is a /+ nesting +/ comment
  6. +/
  7. enum COMPILED_ON = __TIMESTAMP__; // special token
  8. enum character = '©';
  9. enum copy_valid = '©';
  10. enum backslash_escaped = '\\';
  11. // string literals
  12. enum str = `hello "world"!`;
  13. enum multiline = r"lorem
  14. ipsum
  15. dolor"; // wysiwyg string, no escapes here allowed
  16. enum multiline2 = "sit
  17. amet
  18. \"adipiscing\"
  19. elit.";
  20. enum hex = x"66 6f 6f"; // same as "foo"
  21. #line 5
  22. // float literals
  23. enum f = [3.14f, .1, 1., 1e100, 0xc0de.01p+100];
  24. static if (something == true) {
  25. import std.algorithm;
  26. }
  27. void main() pure nothrow @safe {
  28. ulong lines = 0;
  29. double sumLength = 0;
  30. foreach (line; stdin.byLine()) {
  31. ++lines;
  32. sumLength += line.length;
  33. }
  34. writeln("Average line length: ",
  35. lines ? sumLength / lines : 0);
  36. }