On Tue, Mar 25, 2014 at 8:36 AM, Norbert Hartl <norbert@hartl.name> wrote:


Am 25.03.2014 um 00:33 schrieb "phil@highoctane.be" <phil@highoctane.be>:

On Tue, Mar 25, 2014 at 12:11 AM, Eliot Miranda <eliot.miranda@gmail.com> wrote:



On Mon, Mar 24, 2014 at 4:02 PM, phil@highoctane.be <phil@highoctane.be> wrote:
I am curious.

Maybe on the first one, substitute something when a DNU is encountered.
Like logging undefined receivers.

I wonder how the next one behaves on JITted methods. I fear that offset errors may lead to weird errors.

It *should* "just work" :-) (provided the jump distance of -12 is correct). �The VM traps assignments to variables of contexts, and converts them to vanilla contexts. �Therefore the jump doesn't occur in JITTED code but back in normal interpreted bytecode.


How magical!
On Mon, Mar 24, 2014 at 11:51 PM, Pavel Krivanek <pavel.krivanek@gmail.com> wrote:
Who can find the most useful usage of this?

thisContext instVarNamed: #receiver put: 42.
self factorial

GOTO statement in Pharo:

FileStream stdout nextPutAll: 'Hello world'; lf.�
thisContext jump: -12.
Let's collect the next ones :-)

this is my favourite, and would lock-up a strict blue book VM. �(I once locked up Allen Wirfs-Brock's 4404 with this and he wasn't best pleased [forgive me Allen])


| a |
a := Array with: #perform:withArguments: with: nil.
a at: 2 put: a.
a perform: a first withArguments: a

;-)

The infinite is near.

Not as blocking, but still... (Alt-. interrupts this one)

Crazy>>run
Continuation currentDo: [ :cc | here := cc ].
here value: true.
Crazy new run

BTW, is there any support for partial continuations in Pharo? Continuations like this one look like full continuations and that's *huge*.

If you mean delimited continuations have a look here:


Thanks. I saw a mention of this but not that article.

Now, I loaded the code in Pharo3 and there are missing methods in BlockContext...

ControlTests>>testNestedShiftResetNest (I guess other things would say the same) is broken

testNestedShiftResetsNest
| innerCont outerCont |
[1 + [ :k |
outerCont := k. "stack reified as [ :x | 1 + x ]"
k value: [ 2 + [ :kk |
innerCont := kk. "stack reified as [ :x | 2 + x ]"
kk value: 0 ] shift ] reset ] shift ] reset.

self assert: 3 equals: (innerCont value: 1).
self assert: 2 equals: (outerCont value: 1).
self assert: 5 equals: ((outerCont compose: [:x | x * 2]) value: 2)

due to MethodContext's DNU: copyTo:bottomContextDo:�


Inline image 1

There is a ContextPart: aContext blocks: dict but but looking like the same thing.

Composition tests do work.

Gurus welcome... If we put continuations in the Pharo image, why not put this as well?

Phil
Norbert�


Cheers,
-- Pavel




--
best,
Eliot