confused about string and lambda args

mark mark at qtrac.eu
Thu Jan 16 17:03:33 UTC 2020


I'm looking at 
https://tour.dlang.org/tour/en/gems/range-algorithms
(IMO the example code is far too long and complicated.)
But here's the thing:

     auto wordCharCounts = words // I added this and it works fine
         .map!"a.length";
     writeln(wordCharCounts);

     auto wordCharCounts2 = words // I added this and it works fine
         .map!(a => a.length);
     writeln(wordCharCounts2);

     auto wordCharCounts3 = words // this is in the tutorial
       .map!"a.count";
     writeln(wordCharCounts3);

     auto wordCharCounts4 = words // I added this and it won't 
compile
       .map!(a => a.count); // Error: no property count for type 
string
     writeln(wordCharCounts4);

I don't understand why both syntaxes work for .length but only 
the string form for .count?


More information about the Digitalmars-d-learn mailing list