d***@googlemail.com
2012-03-15 14:26:55 UTC
Hello everyone,
I've just started to learn Smalltalk and struggled over the concept of continuations.
As far as I understand continuations they are objects holding the full state of a process (including the full call-stack, the program counter and locale variables). When using such a continuation to resume a process, than the current process should be reset to the state described within the continuation object. I thought it would be obvious that the program counter would be reset as well to the next statement after the definition of the continuation: but it doesn't seem to work like this.
See the following example:
We have a class named "SomeClass" with an instance-method "doSomething", defined as follows:
doSomething: aBlock
aBlock value.
^'Hello from inside method'
Now we use the method in the workspace like this:
| returnValue |
returnValue := SomeClass1 new doSomething: [ Transcript show: 'Hello from closure'.
^'Some return value from the closure' ].
Transcript show: 'The method returned ' , returnValue.
If you execute the code within the workspace you will only see the single output:
Hello from Closure
Obviously the value 'Hello from inside method" will NOT be returned, because the return statement inside the closure will reset the process to the continuation-object state. But shouldn't this mean, that we should return to the next statement within the workspace, i.e. "Transcript show: 'The method returned' , returnValue.'?
Thanks for you help,
Dirk
I've just started to learn Smalltalk and struggled over the concept of continuations.
As far as I understand continuations they are objects holding the full state of a process (including the full call-stack, the program counter and locale variables). When using such a continuation to resume a process, than the current process should be reset to the state described within the continuation object. I thought it would be obvious that the program counter would be reset as well to the next statement after the definition of the continuation: but it doesn't seem to work like this.
See the following example:
We have a class named "SomeClass" with an instance-method "doSomething", defined as follows:
doSomething: aBlock
aBlock value.
^'Hello from inside method'
Now we use the method in the workspace like this:
| returnValue |
returnValue := SomeClass1 new doSomething: [ Transcript show: 'Hello from closure'.
^'Some return value from the closure' ].
Transcript show: 'The method returned ' , returnValue.
If you execute the code within the workspace you will only see the single output:
Hello from Closure
Obviously the value 'Hello from inside method" will NOT be returned, because the return statement inside the closure will reset the process to the continuation-object state. But shouldn't this mean, that we should return to the next statement within the workspace, i.e. "Transcript show: 'The method returned' , returnValue.'?
Thanks for you help,
Dirk