Evaluation Strategy

Table of Contents

Call By Value

Copies the arguments into the callee.

Pros:

Cons:

Call By Reference

Passes arguments as references into callee.

Pros:

Cons:

Call By Result

Passes arguments into the function, with 1 of them being a reference to the result that the function fills in.

Pros:

Cons:

Call By Value-Result

Same as call by result, but that parameter that will contain the value, will also be used as a variable before the answer is filled in.

Pros:

Cons:

Call By Name

Calls by name sends the full expression as variables into the function.

For something like:

void f(... a, ... b){
    ...
}

f(x+1, x)

We are legitimately sending an lvalue expression(x+1) that is not yet evaluated, and an rvalue expression(x) that is also not yet evaluated(we don’t know its address) into f.

To get the value out, we kind of treat them as lambdas, and a will give us an lvalue and b will give us an rvalue address. We will be updating whatever x we were using, as if it was passed by reference.

Pros:

Cons:

Call By Need

The same as call by name, but memoizes the results of the computation. a and b are bounded to the results after their first evaluation.

However, this gives different side-effects:

void f(by-need int a, by-need int b){
    b = a; // 'i = i+1' -> gives us &i = 4.
    // a -> 4
    // b -> &i
    b = a; // Already cached: &i = 4.
}

void g(){
    int i = 3;
    f(i+1, i);
    return i;
}

Pros:

Cons: