Website message overhaul

Timon Gehr timon.gehr at gmx.ch
Mon Nov 14 14:44:00 PST 2011


On 11/14/2011 11:30 PM, bearophile wrote:
> 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.
>

Some people like query-style formatting:

auto answer = recurrence!q{ a[n-1] + a[n-2] }(1, 1)
              .until!q{ a>  4_000_000 }()
              .filter!isEven()
              .sum();

> 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

If UFCS is going to work, then that should ideally work too. Probably 
what is a little bit problematic here is that it is parsed as 
(b.tail)!int().

b.tail gets rewritten to tail(b) per UFCS and property syntax. And that 
is not a template anymore.





More information about the Digitalmars-d mailing list