Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

When I think of "call by expression" I think of R. Are there other languages that are call by expression?

I don't know how this compares to others. But it seems weird to me that you get only the value and only the text expression. There's no AST. You don't get some first-class closure of the elements that make up the expression that you could compute on. You also seem to have to compute the expression ahead of time.

Ideally I'd love to have a full AST of the expression, with all the intermediary values filled in. Or perhaps, like, an AST with nothing computed, that I can then compute myself.

So I guess, like, the intent here is not call by expression. It's meant to inform, but not to allow the callee to compute.



Do expression trees [0] line up with what R has? I'm not familiar with R's "call by expression" syntax.

[0] https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...


In R, every function argument may be 1) ignored, 2) accessed as an AST, 3) passed to another function, or 4) accessed as a value, or some combination thereof. Note that 1, 2, and 3 don’t result in the expression being evaluated, as function arguments are lazy in R. There’s no way to look at only a function’s signature and determine whether a given argument is going to be evaluated never, once, or multiple times, or conditionally (though the vast majority of the time it’s “once”).

On the plus side it does allow for some extremely elegant libraries to be written.


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.


The expressions you mention are already there (Expression trees, since C#3 IIRC?), it was required for the LINQ features.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: