<p>There are three standard <a href="https://en.wikipedia.org/wiki/Evaluation_strategy" rel="nofollow noreferrer">evaluation strategies</a> for the <a href="https://en.wikipedia.org/wiki/Lambda_calculus" rel="nofollow noreferrer">lambda calculus</a>:</p>
<ul>
<li><a href="https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value" rel="nofollow noreferrer">Call-by-value</a> (CBV)</li>
<li><a href="https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_name" rel="nofollow noreferrer">Call-by-name</a></li>
<li><a href="https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_need" rel="nofollow noreferrer">Call-by-need</a></li>
</ul>
<p>There are two variants of CBV that differ on how they behave with respect to <a href="https://en.wikipedia.org/wiki/Lambda_calculus#anApplic" rel="nofollow noreferrer">applications</a>:</p>
<ul>
<li>Left-to-right: Evaluates the function first</li>
<li>Right-to-left: Evaluates the argument first</li>
</ul>
<p>These are described in greater detail in sections 6.1 and 6.2, respectively, of [1].</p>
<p>What are the advantages and disadvantages of each approach?</p>
<hr />
<p>References:</p>
<ol>
<li><a href="https://arxiv.org/abs/1406.2370" rel="nofollow noreferrer">Distilling Abstract Machines (Long Version)</a>. Beniamino Accattoli, Pablo Barenbaum, Damiano Mazza. 2014-06-09.</li>
</ol>

<language-design><implementation><semantics><functional-programming><lambda-calculus>
Call-by-value: Left-to-right vs right-to-left
CC BY-SA 4.0
2023-07-27T18:29:31.910Z
The question should make clear if it is about functional languages or about parameter passing in general. If the focus is functional languages, it should make clear if it is only about pure semantics or about real world functional languages.
feldentm
CC BY-SA 4.0
2023-07-27T22:22:46.917Z
The question seems to ask about subjective, practical assessment of consequences, but that might be a bit difficult to do in terms of pure lambda calculus. *Most* actually implemented, practical languages conceive of functions as potentially having more than one argument, or no arguments; and in a lot of them there isn't meaningful runtime "evaluation" of functions. I'm guessing you specifically have in mind Haskell-family languages, but already there's an answer talking about Java that's hard to relate to the apparent conceptual framework here.
Karl Knechtel
<p>Java uses left to right because this is what most users seem to expect.</p>
<p>Actually, there is another approach: unspecified and let the compiler decide based on whatever it needs or wants to do and let it optimize.</p>
<p>If the question is about languages in general and not specifically about functional languages, the most obvious effect is that on side effects. I.e. f(++x, ++x) can increment either the left or the right first. You get similar effects if you pass two function results with global side effects like reading a file or calling a web server. It doesn't necessarily require mutable entities in your language.</p>

CC BY-SA 4.0
2023-07-27T18:28:15.487Z
2023-07-27T18:28:15.487Z
feldentm
CC BY-SA 4.0
2023-07-27T22:51:16.453Z
The question is talking about 'pure' lambda calculus where functions can only have one argument, so there's no question of ordering between arguments.
Chris Dodd
CC BY-SA 4.0
2023-07-29T11:07:45.490Z
@ChrisDodd By Currying, though, left-to-right evaluation of single-argument applications (`(f (++x)) (++x)`) and left-to-right evaluation of a list of arguments (`f(++x, ++x)`) practically coincide (and similar for right-to-left).
James Wood
# Call-by-value: Left-to-right vs right-to-left
Posted by: username_0 on 2023-07-27
There are three standard [evaluation strategies](https://en.wikipedia.org/wiki/Evaluation_strategy) for the [lambda calculus](https://en.wikipedia.org/wiki/Lambda_calculus):

* [Call-by-value](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_value) (CBV)
* [Call-by-name](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_name)
* [Call-by-need](https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_need)

There are two variants of CBV that differ on how they behave with respect to [applications](https://en.wikipedia.org/wiki/Lambda_calculus#anApplic):

* Left-to-right: Evaluates the function first
* Right-to-left: Evaluates the argument first

These are described in greater detail in sections 6.1 and 6.2, respectively, of [1].

What are the advantages and disadvantages of each approach?

---

References:

1. [Distilling Abstract Machines (Long Version)](https://arxiv.org/abs/1406.2370). Beniamino Accattoli, Pablo Barenbaum, Damiano Mazza. 2014-06-09.
**Tags:** language-design implementation semantics functional-programming lambda-calculus
> **Comments:**
> **username_1**: The question should make clear if it is about functional languages or about parameter passing in general. If the focus is functional languages, it should make clear if it is only about pure semantics or about real world functional languages.  
> **username_2**: The question seems to ask about subjective, practical assessment of consequences, but that might be a bit difficult to do in terms of pure lambda calculus. *Most* actually implemented, practical languages conceive of functions as potentially having more than one argument, or no arguments; and in a lot of them there isn't meaningful runtime "evaluation" of functions. I'm guessing you specifically have in mind Haskell-family languages, but already there's an answer talking about Java that's hard to relate to the apparent conceptual framework here.  
---
## 1 answers
### Answer by username_1 on 2023-07-27. Score: 1
Java uses left to right because this is what most users seem to expect.

Actually, there is another approach: unspecified and let the compiler decide based on whatever it needs or wants to do and let it optimize.

If the question is about languages in general and not specifically about functional languages, the most obvious effect is that on side effects. I.e. f(++x, ++x) can increment either the left or the right first. You get similar effects if you pass two function results with global side effects like reading a file or calling a web server. It doesn't necessarily require mutable entities in your language.
> **Comments:**
> **username_3** (2023-07-27): The question is talking about 'pure' lambda calculus where functions can only have one argument, so there's no question of ordering between arguments.  
> **username_4** (2023-07-29): @ChrisDodd By Currying, though, left-to-right evaluation of single-argument applications (`(f (++x)) (++x)`) and left-to-right evaluation of a list of arguments (`f(++x, ++x)`) practically coincide (and similar for right-to-left).  
---
