unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* please explain prompt scope
@ 2017-10-17 12:38 Matt Wette
  2017-10-20  1:42 ` Matt Wette
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Wette @ 2017-10-17 12:38 UTC (permalink / raw)
  To: Guile User Mailing List

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'?

Thanks much.
Matt




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: please explain prompt scope
  2017-10-17 12:38 please explain prompt scope Matt Wette
@ 2017-10-20  1:42 ` Matt Wette
  2017-10-25  0:22   ` Matt Wette
  0 siblings, 1 reply; 3+ messages in thread
From: Matt Wette @ 2017-10-20  1:42 UTC (permalink / raw)
  To: Matt Wette; +Cc: Guile User Mailing List


> On Oct 17, 2017, at 5:38 AM, Matt Wette <matt.wette@gmail.com> 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: please explain prompt scope
  2017-10-20  1:42 ` Matt Wette
@ 2017-10-25  0:22   ` Matt Wette
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Wette @ 2017-10-25  0:22 UTC (permalink / raw)
  To: Guile User Mailing List


> On Oct 19, 2017, at 6:42 PM, Matt Wette <matt.wette@gmail.com> wrote:
> 
> 
>> On Oct 17, 2017, at 5:38 AM, Matt Wette <matt.wette@gmail.com> 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-25  0:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-17 12:38 please explain prompt scope Matt Wette
2017-10-20  1:42 ` Matt Wette
2017-10-25  0:22   ` Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).