Types of lambda args
Paul Backus
snarwin at gmail.com
Wed Aug 26 16:47:58 UTC 2020
On Wednesday, 26 August 2020 at 15:57:37 UTC, Cecil Ward wrote:
>
> Ah! That’s the vital missing piece - I didn’t realise it was
> like a template - I just thought it was an ordinary plain
> anonymous function, not a generic. All makes sense now.
Fun fact: you can see the "de-sugared" version of many language
constructs like this by looking at the compiler's AST output. For
example, given a source file `lambda.d` with the following
contents:
alias fun = (x) => x*x;
The command `dmd -vcg-ast lambda.d` produces as output the file
`lambda.d.cg`, with the following contents:
import object;
alias fun = __lambda3(__T1)(x)
{
return x * x;
}
;
The syntax is a little different from normal D code, but you can
see the template argument `__T1` appear in addition to the
function argument `x`.
More information about the Digitalmars-d-learn
mailing list