## Continuations in Scala - Escapers and evaluation

Jannis
Mausschubser
Beiträge: 63
Registriert: 15. Apr 2015 17:10

### Continuations in Scala - Escapers and evaluation

Hello!

How are continuations in Scala evaluated? In the examples of V08-Continuations.pdf (slide 31 and 32), we say that we need Escapers to correctly evaluate these expressions.

But when we halt the computation after the execution of k, we are not able to nest the continuation function like in the following expression (A):

Code: Alles auswählen

reset {
1 + shift {k: (Int => Int) => k(k(1))}
}

When executed in Scala, this returns 3 and therefore would imply that we actually do not halt the computation after the execution of k.

When I take a look at the evaluation of the expression from slide 32 (B):

Code: Alles auswählen

reset {
1 + shift { k: (Int => Int) => k(3) }
}

we say that this evaluates to 1 + k(3) and returns the correct result (4) because k is an escaper function. But looking at the code example A, could it be possible that the term actually evaluates to k(3) == 1 + 3 == 4 instead without using any escaping?

VSchü
Windoof-User
Beiträge: 26
Registriert: 5. Jul 2015 16:46

### Re: Continuations in Scala - Escapers and evaluation

Hi,
in Scala, everything inside of reset but outside of shift is captured as "the rest of the computation" and bound to k. Escapers do not actually exist in Scala syntax, thats why slide 32 states "We will symbolically use the notation [..]". On slide 31 we try to understand what the continuation for the given example is, i.e. what is bound to k. The proposed function does not work as expected, therefore the escaper notation is used to underline the problem. But Scala already does the correct computation for you, without the need to manually add the escaper.