[plt-scheme] map and call/cc bug with amb-collect?

From: Andre van Tonder (andre at het.brown.edu)
Date: Thu May 22 12:15:15 EDT 2003

I'm having a problem making amb-collect from swindle work with the
built-in map function.  The same code works if I define my own map
function.  I suspect there may be a subtle bug involving map
and call/cc, but I haven't had any luck figuring it out so far.   

;; Beginning of code snippet

(require (lib "swindle.ss" "swindle"))

(define (f x) 
  (amb 0 1))

; This gives the wrong result:

(amb-collect (map f '(0 0)))
                             ; => ((0 1) (0 1) (1 1) (1 1))

; Compare with a hand-rolled map function:

(define (my-map f lst)
  (if (empty? lst) 
      empty
      (cons (f (first lst))
            (my-map f (rest lst))))) 

; This now gives the correct result:

(amb-collect (my-map f '(0 0)))
                               ; => ((0 0) (0 1) (1 0) (1 1))

; However, note that the following does give a correct sequence:

(map f '(0 0))   ; => (0 0)
(amb)            ; => (0 1)
(amb)            ; => (1 0)
(amb)            ; => (1 1)

;; End of code snippet


Any remarks would be appreciated.

Regards
Andre



Posted on the users mailing list.