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


Mikael Djurfeldt <mdj@nada.kth.se> writes:

Sorry, I'm tired.  A continuation was required.  This version has the
advantage that it's safe for both routine1 and routine2 to "fall off
the edge".

  (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) ...)))
    (call/cc (lambda (return)
               (call/cc (lambda (k)
			 (set! saved-continuation k)
		         (return (routine1))))
               (routine2))))