1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00
guile/testsuite/t-call-cc.scm
Andy Wingo 46d2d6f80e allocate variables that are set! on the heap
* module/system/il/ghil.scm (ghil-lookup): So, it turns out this function
  needed to be split into three:
  (ghil-var-is-bound?, ghil-var-for-ref!, ghil-var-for-set!): The
  different facets of ghil-lookup. Amply commented in the source. The
  difference being that we now allocate variables that are set! on the
  heap, so that other continuations see their possibly-modified values.
  (force-heap-allocation!): New helper.

* testsuite/Makefile.am:
* testsuite/t-call-cc.scm: New test, that variables that are set! are
  allocated on the heap, so that subsequent modifications are still
  seen by the continuation. The test was distilled from test 7.3 in
  r5rs_pitfall.test.
2008-09-28 23:09:11 +02:00

16 lines
447 B
Scheme

(let ((set-counter2 #f))
(define (get-counter2)
(call/cc
(lambda (k)
(set! set-counter2 k)
1)))
(define (loop counter1)
(let ((counter2 (get-counter2)))
(set! counter1 (1+ counter1))
(cond ((not (= counter1 counter2))
(error "bad call/cc behaviour" counter1 counter2))
((> counter1 10)
#t)
(else
(set-counter2 (1+ counter2))))))
(loop 0))