digitalmars.D.learn - Predicates Within Strings
- Justin Choi (8/8) Jun 14 2021 Could somebody explain or point me to documentation that helps to
- jfondren (23/31) Jun 14 2021 The strings are just strings. If you look at the implementation
Could somebody explain or point me to documentation that helps to explain the usage of strings in predicates? My main question is how D infers the omitted variable specifications given otherwise - for example: `filter!(a => a < 3)(arr);` and `filter!"a < 3"(arr);` produce the same result.
Jun 14 2021
On Monday, 14 June 2021 at 15:01:01 UTC, Justin Choi wrote:Could somebody explain or point me to documentation that helps to explain the usage of strings in predicates? My main question is how D infers the omitted variable specifications given otherwise - for example: `filter!(a => a < 3)(arr);` and `filter!"a < 3"(arr);` produce the same result.The strings are just strings. If you look at the implementation for filter you can trace the strings getting to std.functional.unaryFun and friend, which pulls the string apart at compile-time to construct a function. I think this system is pretty cool (terse and clear in usage, and a good demonstration of static parameters in templates) but they have confusing limits since the function is built inside std.functional and not where the user is. That has nothing to do with your main question though. Function literals are documented in https://dlang.org/spec/expression.html#FunctionLiteral which just these remarks: - If the type of a function literal can be uniquely determined from its context, the parameter type inference is possible. - If the function literal is assigned to an alias, the inference of the parameter types is done when the types are needed, as the function literal becomes a template. I don't see a lot of detail about the type inference itself.
Jun 14 2021