Website message overhaul
bearophile
bearophileHUGS at lycos.com
Mon Nov 14 14:30:46 PST 2011
Brad Anderson:
> auto answer = reduce!"a + b"(filter!"a % 2 == 0"(until!"a >
> 4_000_000"(recurrence!"a[n-1] + a[n-2]"(1, 1))));
>
> It'd look better with UFCS but it's still rather neat I think.
reduce!"a + b"() is going to be replaced by std.algorithm.sum().
And I think a isOdd() and isEven are worth putting in Phobos.
So it becomes:
auto answer = sum(filter!isEven(until!q{ a > 4_000_000 }(recurrence!q{ a[n-1] + a[n-2] }(1, 1))));
And maybe like this with UFCS:
auto answer = recurrence!q{ a[n-1] + a[n-2] }(1, 1).until!q{ a > 4_000_000 }().filter!isEven().sum();
And this is even starting to become readable enough.
But is UFCS going to work with explicit template arguments syntax too?
T[] tail(T)(T[] a) {
return a[1 .. $];
}
void main() {
auto b = [10, 20, 30];
assert(b.tail().tail() == [30]); // OK
assert(b.tail!int().tail!int() == [30]); // Error: tail(b) isn't a template
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list