Hi all,

I'm trying to understand how continuations work, and tried out the first example described at "https://en.wikibooks.org/wiki/Scheme_Programming/Continuations"; with Chicken (5.1):

-----------------------------------------------
(define continuations '())

(define (push arg)
  (set! continuations
(cons arg continuations)))

(define (capture-from-map arg)
  (call-with-current-continuation
   (lambda (cc)
     (push cc)
     arg)))

(define numbers (map capture-from-map '(1 2 3 4 5 6)))

;;REPL
numbers
(1 2 3 4 5 6)
((car (reverse continuations)) 76)
((result "#<unspecified>") (output . ""))
numbers
(1 2 3 4 5 6 76 2 3 4 5 6)
-----------------------------------------------

To my surprise, this last value stored at 'numbers' differs from other implementations (and from the example described on the Wiki):
Guile/Racket/MIT: (76 2 3 4 5 6)
Chez: (1 2 3 4 76 6)

Could someone please explain what's going on? Why would Chicken append the new list to the old value of 'numbers', which as I understand should be empty at the moment of the stored continuation?

Regards,

Ricardo


_______________________________________________
Chicken-users mailing list
Chicken-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to