guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: please explain prompt scope


From: Matt Wette
Subject: Re: please explain prompt scope
Date: Tue, 24 Oct 2017 17:22:47 -0700

> On Oct 19, 2017, at 6:42 PM, Matt Wette <address@hidden> wrote:
> 
> 
>> On Oct 17, 2017, at 5:38 AM, Matt Wette <address@hidden> wrote:
>> 
>> Here is a program that uses prompt and capture the continuation in top-level 
>> binding.
>> 
>> (define (sf fmt . args) (apply simple-format #t fmt args))
>> 
>> (define At (make-prompt-tag))
>> 
>> (define Ak #f)
>> 
>> (let ((a 2))
>> (call-with-prompt At
>>   (lambda ()
>>     (sf "hello\n")
>>     (abort-to-prompt At)
>>     (sf "world where a=~S\n" a))
>>   (lambda (k . args)
>>     (set! Ak k)
>>     (sf "!\n")))
>> (set! a 99))
>> 
>> (Ak)
>> 
>> Here is the output:
>> hello
>> !
>> world where a=99
>> 
>> Can someone explain how `a' is captured in the continuation?
>> Does the continuation include the stack outside `prompt'?
> 
> I am reading up on this now:
>       Sec 9.3 of the Guile 2.2 Manual 
> and
>       https://www2.ccs.neu.edu/racket/pubs/lasc1990-sf.pdf

I think I understand this now.  The abort only saves the stack context up to 
the associated call-with-prompt.  
Since `a' is `set!' is it boxed in heap and the continuation includes a 
reference to that box in heap.  I'm 
guessing if `a' was not set that the unboxed value would be contained in the 
continuation and the binding to
`a' is not needed in the continuation.  Does that sound right?

Matt





reply via email to

[Prev in Thread] Current Thread [Next in Thread]