On 24 March 2014 23:33, [email protected] <[email protected]> wrote:
> On Tue, Mar 25, 2014 at 12:11 AM, Eliot Miranda <[email protected]>
> wrote:
>>
>>
>>
>>
>> On Mon, Mar 24, 2014 at 4:02 PM, [email protected] <[email protected]>
>> 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
>>> <[email protected]> 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*.

Yes: http://ss3.gemstone.com/ss/Control.html

Last time I checked I did need to add a shim (see the ControlPharo
package), but it did load cleanly and pass all its own tests.

Control not only provides a convenient way of making partial
continuations (of the shift/reset sort, if you're familiar with the
literature), but also _delimited_ dynamic variables. As soon as you
start stack-slicing with partial continuations, you quickly find that
standard implementations of dynamic variables fail in all sorts of
nasty ways. Fundamentally, "normal" dynamic variables _cannot_ work
cleanly with partial continuations because they either close over too
much of the dynamic environment, or too little.

Here's some reading on the topic:

[1] http://okmij.org/ftp/Computation/dynamic-binding.html
[2] http://www.cs.rutgers.edu/~ccshan/dynscope/DDBinding.pdf
[3] 
http://www.lshift.net/blog/2012/06/27/resumable-exceptions-can-macro-express-delimited-dynamic-variables

frank

>>>> Cheers,
>>>> -- Pavel
>>>
>>>
>>
>>
>>
>> --
>> best,
>> Eliot
>
>

Reply via email to