This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: searching an explanation: call/cc and 'do' strangeness


Per Bothner <bothner@cygnus.com> writes:

> So something like this should work:
> 
> (let
>   ((saved-continuation ...)
>    (suspend (lambda (value)
>              ;; swap current continuation and saved-continuation
>              (call/cc (lambda (k)
> 	               (let ((ksaved saved-continuation))
> 			    (set! saved-continuation k)
> 			    (ksaved value))))))
>    (routine1 (lambda () ... (suspend x) ...))
>    (routine2 (lambda () ... (suspend y) ...)))
>   (routine1))
> 
> Admittedly, this glosses over some of the difficult parts,
> such as how saved-continuation is initialized (to run routine2).
> 
> What am I missing?

How about

 (let
   ((saved-continuation ...)
    (suspend (lambda (value)
              ;; swap current continuation and saved-continuation
              (call/cc (lambda (k)
 	               (let ((ksaved saved-continuation))
 			    (set! saved-continuation k)
 			    (ksaved value))))))
    (routine1 (lambda () ... (suspend x) ...))
    (routine2 (lambda () ... (suspend y) ...)))
   (set! saved-continuation (lambda (init) (routine2)))
   (routine1))

?