On Monday, 1 August 2022 at 14:52:03 UTC, pascal111 wrote:
If `foo => bar` == `(foo) { return bar; }`, then `foo => bar` is a function. "=>" is not an operator, it's a special symbol for lambda "function".

If A == B, so A's types is the same of B's type. How can it be withstanding `foo => bar` == `foo => bar` == `(foo) { return bar; }` and `foo => bar` is an expression and the other is a function?!! no sense.

From [the relevant section of the language spec:][1]

FunctionLiterals (also known as Lambdas) enable embedding anonymous functions and anonymous delegates directly into expressions. [...] The type of a function literal is a delegate or a pointer to function.

In other words, a function literal is an expression that evaluates to either a delegate or a function pointer.

You are correct that, strictly speaking, it is wrong to say that a function literal "is" an anonymous function (rather than "refers to" or "points to" one). However, the distinction usually does not matter in practice, so most D programmers use the terms interchangeably.

[1]: https://dlang.org/spec/expression.html#function_literals

Reply via email to