On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
I assume the purpose for those demonstrations are to win the
interest of the user as to how easy and clean D code can be.
// Round floating point numbers
import std.algorithm, std.conv, std.functional,
std.math, std.regex, std.stdio;
alias round = pipe!(to!real, std.math.round, to!string);
static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;
// Replace anything that looks like a real
// number with the rounded equivalent.
.map!(l => l.replaceAll!(c => c.hit.round)
How is a new visitor supposed to know "!" is for templates and
not some complicated syntax?
How's a new user supposed to know <> is for templates when
looking at a C++ example? They don't; it's just something that
has to be learned, or they know it because other languages use a
similar syntax. Rust uses ! for macro invocation, and I imagine
that creeps into some of their examples (OTOH, anything that
prints output). Templates are such an integral part of D that any
non-trivial example can't get around not using them.