3 ms·
In C#, you don't have implicit call-by-expression, but explicit is possible like so: void Foo(Expression<Func<int, int>> f) { ... } Foo(x => x + 1); Th
by int_19h 5y ago
In C#, you don't have implicit call-by-expression, but explicit is possible like so:
void Foo(Expression<Func<int, int>> f) { ... }
Foo(x => x + 1);
The call syntax is just a regular lambda. But in this case, instead of getting a function, you get the AST for its body. Which can be compiled to an actual function and then invoked if desired, or inspected and used for other purposes.
I think having it explicit is a good idea, since it tells the caller that something funky is going on. The corresponding feature in R has to be implicit to allow the rest of the language to be desugared into function calls (in R, even assignments, statement-separating semicolons, and function definitions are handled that way). It's neat conceptually, but now every single function call can do crazy things - and some libraries make use of that.