confused about string and lambda args

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jan 16 18:21:34 UTC 2020


On Thu, Jan 16, 2020 at 05:03:33PM +0000, mark via Digitalmars-d-learn wrote:
[...]
>     auto wordCharCounts4 = words // I added this and it won't compile
>       .map!(a => a.count); // Error: no property count for type string
>     writeln(wordCharCounts4);

You need to import std.algorithm to get `count`.


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

Because .length is a property of strings, whereas .count is actually not
a string property, but a function that's being called via UFCS: Unified
Function Call Syntax, in which when the compiler sees something like:

	obj.func(x, y, z);

but `obj` doesn't have a member named `func`, then it will try to
rewrite it into:

	func(obj, x, y, z);

instead.


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose Bierce


More information about the Digitalmars-d-learn mailing list