Fw: [plt-scheme] Confusing continuation behavior (a question about)
----- Original Message -----
From: "Anton van Straaten" <anton at appsolutions.com>
To: "Jos Koot" <jos.koot at telefonica.net>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Friday, July 18, 2008 2:29 AM
Subject: Re: Fw: [plt-scheme] Confusing continuation behavior (a question
about)
> Sorry, I didn't mean to be so blunt about it - I was too focused on the
> problem.
I have the one to be sorry. I did not take your remark as blunt. It was
right.
May be the following does what is wanted (just following the recipe):
#lang scheme
(define cond1 #f)
(define cond2 #f)
(define (foo-process arg1 arg2 name)
(define (toggle (arg 'ignore))
(let ((old-state state))
(let/cc cc (set! state cc)
(old-state arg))))
(define (state ignore)
(define done1 #f)
(define done2 #f)
(printf "~a Passed in args ~a and ~a~n" name arg1 arg2)
(let loop ()
(unless done1
(if cond1
(begin
(set! done1 #t)
(printf "~a Condition 1 is met, going to condition 2~n" name))
(begin
(toggle (list name "Condition 1 not met"))
(loop)))))
(let loop ()
(if cond2
(begin
(set! done2 #t)
(printf "~a Condition 2 is met, can finish the process~n" name))
(begin
(toggle (list name "Condition 2 not met"))
(loop))))
(printf "The process has finished with values ~a and ~a~n" arg1 arg2)
(let ((result (+ arg1 arg2)) (old-state state))
(set! state (lambda (ignore) (error 'process "~a called after finish"
name)))
(old-state result)))
toggle)
(define a-process (foo-process 13 29 'aaa))
(define b-process (foo-process 665 1 'bbb))
(a-process)
(set! cond1 #t)
(a-process)
(set! cond2 #t)
(a-process)
(b-process)
;Welcome to DrScheme, version 4.0.2.3-svn17jul2008 [3m].
;Language: Module; memory limit: 600 megabytes.
;aaa Passed in args 13 and 29
;(aaa "Condition 1 not met")
;aaa Condition 1 is met, going to condition 2
;(aaa "Condition 2 not met")
;aaa Condition 2 is met, can finish the process
;The process has finished with values 13 and 29
;42
;bbb Passed in args 665 and 1
;bbb Condition 1 is met, going to condition 2
;bbb Condition 2 is met, can finish the process
;The process has finished with values 665 and 1
;666
;>
>
>
> Anton
>
>
> Jos Koot wrote:
>>
>>
>>
>> Oops. So sorry.
>> Jos
>>>
>>> ----- Original Message ----- From: "Anton van Straaten"
>>> <anton at appsolutions.com>
>>> To: "Grant Rettke" <grettke at acm.org>
>>> Cc: "PLT-list" <plt-scheme at list.cs.brown.edu>
>>> Sent: Friday, July 18, 2008 1:36 AM
>>> Subject: Re: [plt-scheme] Confusing continuation behavior (a question
>>> about)
>>>
>>>
>>>
>>>> 2. Jos Koot's solution doesn't achieve the desired effect, since it
>>>> simply re-executes the whole of 'impl' every time. impl is local with
>>>> respect to 'process', so the effect of the set! is lost once control
>>>> transfers out of the procedure. This can be seen in the output which
>>>> repeats "Condition 1 is met, going to condition 2" three times.)
>>>>
>>>> Anton
>>>> _________________________________________________
>>>> For list-related administrative tasks:
>>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>
>>
>> _________________________________________________
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme