0

I'm trying to test the continuation facility in Pharo, with this code(in the playground):

| cont f |
f:=[
    |i|
    i:=0.
    Continuation currentDo: [ :cc | cont:=cc ].
    i:=i+1.
].
f value. "1"
cont. "a Continuation"

However, as soon as I call the continuation saved in cont(replacing cont. by cont value.), the image freezes immediately, and I have to press atl+. to gain back control.

VM version: VM: NBCoInterpreter NativeBoost-CogPlugin-GuillermoPolito.19 uuid: acc98e51-2fba-4841-a965-2975997bba66 May 15 2014 NBCogit NativeBoost-CogPlugin-GuillermoPolito.19 uuid: acc98e51-2fba-4841-a965-2975997bba66 May 15 2014 https://github.com/pharo-project/pharo-vm.git Commit: ed4a4f59208968a21d82fd2406f75c2c4de558b2 Date: 2014-05-15 18:23:04 +0200 By: Esteban Lorenzano <estebanlm@gmail.com> Jenkins build #14826

Pharo version: [version] 4.0 #40614

Thanks.

Edit: I was stupid, didn't think this through...

Charles Langlois
  • 4,198
  • 4
  • 16
  • 25
  • well... not I was able to reproduce it, but adding the execution of the continuation (cont value) at the end of your script... you should add that part in your explaining script, otherwise is not comprensible. Anyway... let me see what can we do and I'll go back here. – EstebanLM Jun 22 '15 at 06:22

2 Answers2

2

You've effectively created an infinite loop by reevaluating the same code again and again. You can see that if you debug the code and step through it. The original context will always be restored and then evaluated starting with the first expression following the #currentDo: send. This is exactly what the continuation is supposed to do: save the current position in the execution and restart there later on.

Max Leske
  • 5,007
  • 6
  • 42
  • 54
  • I don't see how this is an infinite loop. When the continuation is executed, the execution starts at `i:=i+1`, then reach the end of the block. It should then return the result, no? There's no looping involved... However, putting a return at the end does work. Thanks. – Charles Langlois Jun 21 '15 at 17:15
  • Yes, you reach the end of the block *but in the context it was originally executed in*. That means, that `cont value` will also be executed again. And there's your loop. – Max Leske Jun 21 '15 at 17:44
  • Oh, I get it, sorry. Thanks. – Charles Langlois Jun 21 '15 at 21:19
1

I do not have a Fedora to test, however I tried your code in Ubuntu, using this version of Pharo:

wget -O- get.pharo.org/40+vm | bash
./pharo-ui Pharo.image

and your code seems to work properly :(

In case this error persists, could you be more specific about the version of the vm you are using?:

./pharo Pharo.image --version

And the version of Pharo you are using?:

./pharo Pharo.image printVersion

Also, send us the crash.dmp file would help a lot.

EstebanLM
  • 4,252
  • 14
  • 17
  • VM version: `VM: NBCoInterpreter NativeBoost-CogPlugin-GuillermoPolito.19 uuid: acc98e51-2fba-4841-a965-2975997bba66 May 15 2014 NBCogit NativeBoost-CogPlugin-GuillermoPolito.19 uuid: acc98e51-2fba-4841-a965-2975997bba66 May 15 2014 https://github.com/pharo-project/pharo-vm.git Commit: ed4a4f59208968a21d82fd2406f75c2c4de558b2 Date: 2014-05-15 18:23:04 +0200 By: Esteban Lorenzano Jenkins build #14826` Pharo version: `[version] 4.0 #40614`. – Charles Langlois Jun 18 '15 at 08:31
  • And when I say "crash" I mean "freeze" and I need to kill it myself. There's no crash.dmp file. – Charles Langlois Jun 18 '15 at 08:37
  • 1
    Then is not a vm problem but an image one... you can try stoping the execution (just hit alt+. several times)... In any case, same code does not freezes for me, did you try that in a clean image or is an image with your modifications? – EstebanLM Jun 18 '15 at 10:10
  • I've now tried it with a new installation and new image, still the same problem. I am able to unfreeze with `atl+.`, which shows me the code for the `restoreValues` method, with the following line highlighted: `to: context class instSize do: [:i | context instVarAt: i put: valueStream next].` – Charles Langlois Jun 18 '15 at 10:58
  • I'm also not able to reproduce your problem. What do you mean by "calling the continuation"? You aren't using the continuation in any way in the code you posted. Are you maybe doing more than what the code above does? – Max Leske Jun 19 '15 at 07:01
  • Calling the continuation => `cont value.` As soon as I add "`value`" to the last line in the code above, it freezes. – Charles Langlois Jun 19 '15 at 20:28