; Ok. Let's set up a few structures for the problem. ; For Gambit-C undefine the following ;(define-structure house nationality color drinks smokes pet) ; For Chicken uncomment the following (define-record house nationality color drinks smokes pet) (define (show-house h) (pretty-print "House:") (pretty-print (house-nationality h)) (pretty-print (house-color h)) (pretty-print (house-drinks h)) (pretty-print (house-smokes h)) (pretty-print (house-pet h))) ; Now let us pick the values of the houses on the street (set! *street* (list (make-house (amb 'Brit 'Swede 'Dane 'Norwegian 'German) (amb 'Red 'Green 'White 'Blue 'Yellow) (amb 'Tea 'Milk 'Coffee 'Beer 'Water) (amb 'PallMall 'Dunhill 'Marlboro 'Winfield 'Rothmans) (amb 'Dogs 'Cats 'Horses 'Birds 'Fishes))
;No two owners have the same nationality or pet, smoke the same brand or drink the same beverage. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; FAILS HERE - should iterate till it picks Brit, Swede ;; Instead stops at first iteration (changes dog to cat) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (eq? (house-nationality (car *street*)) (house-nationality (cadr *street*))) (amb))
;And print out the result! (map (lambda (h) (show-house h)) *street*)