Suppose, there is a reset block with a single shift:
val r = reset {
// do smth. 1
shift {...}
// do smth. 2
// do smth. 3
}
Is it correct that I place the shift after “do smth. 2” or “do smth. 3” without changing the result r? Is it correct that it does not matter where shift stands in a reset block?
It highly depends on what you are making within
shift. If you just calling provided function like this:shift((k: Unit => Unit) => k(Unit))then, in your particular example, it really doesn’t matter whereshiftstands.Shiftfunction just captures code that comes after it in other function (in my example this function is calledk). In other words, this code:would be rewritten by compiler in something like this (this code just demonstrates general idea and it’s not supposed to show what compiler plugin will actually generate):
But if you have some logic inside
shift, like conditionalkexecution, then it really matters where thisshiftstands.Hope this helps (and I hope, that I understood your question correctly)