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] |
| Thank you for your answer. Regrettably, we are not quite certain what the | lesson of your answer is. | | Do we have to avoid using the call/cc for all kind of coroutine-style | iterations in datastructures? Or is there a way to encapsulate the usage | of call/cc so that we can trust code outside the encapsulation to behave | predictably? (OK, I guess the behaviour we have observed *is* | predictable, somehow, but only within a global scope of the entire | program). Hmm, folk-law says that continuations can be used to simulate threads, but I've never seen it done. You can't pass the current continuation into scopeWalkDemo as a parameter, since the binding would be captured. Maybe passing it in a variable would be helpful: (define invocation-demo #f) (define return #f) (define scopeWalkDemo (lambda (continuation) (let ((result #f)) (set! invocation-demo (if (not continuation) (call-with-current-continuation invocation-demo) (call-with-current-continuation (lambda (found) (let ((l (list 'cow 'horse 'pig ))) (do ((i 0 (+ i 1))) ((= i (length l))) (set! result (list-ref l i)) (call-with-current-continuation found)) (set! result #f)))))) (return result)))) (define v-demo (make-vector 3)) (do ((j 0 (1+ j)) (cont #t) (tmp #f)) ((>= j 3)) (display (list cont j v-demo))(newline) (vector-set! v-demo j (call-with-current-continuation (lambda (return-cont) (set! return return-cont) (scopeWalkDemo cont)))) (set! cont #f))