3 ms·
I do actually prefer postfix types, so I'm not against you there. The bit about D is that while you CAN write it to look like C, (or even directly embed ASM bl
by gavinray 5y ago
I do actually prefer postfix types, so I'm not against you there.
The bit about D is that while you CAN write it to look like C, (or even directly embed ASM blocks in it), it's usually written in a higher-level form without pointers that looks more like JavaScript:
// Count line length of stdin
void main() {
import std.range, std.stdio;
auto sum = 0.0;
auto count = stdin.byLine.tee!(l => sum += l.length).walkLength;
writeln("Average line length: ", count ? sum / count : 0);
}
----
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.
void main(){
stdin
.byLine
.map!(l => l.replaceAll!(c => c.hit.round)
(reFloatingPoint))
.each!(it => writeln(it));
}