Created
July 28, 2014 11:25
-
-
Save PuercoPop/3abf79d5bfa85c9a3427 to your computer and use it in GitHub Desktop.
File with amb bug for "set!: cannot mutate module-required identifier" on soegaard's sicp.ss that neil's sicp depends on. The bug was caused due to set! being disabled for variables imported by a module: http://docs.racket-lang.org/guide/module-set.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module sicp mzscheme | |
;;; PLT Picture Language | |
(provide (all-from "painters.ss")) | |
(require "painters.ss") | |
;;; STREAMS | |
(provide cons-stream) | |
(define-syntax cons-stream | |
(syntax-rules () | |
[(cons-stream x xs) | |
(cons x (delay xs))])) | |
;;; AMB | |
(provide amb) | |
(require (lib "defmacro.ss")) | |
(define amb-fail '*) | |
(define (initialize-amb-fail) | |
(set! amb-fail | |
(lambda () | |
(error "amb tree exhausted")))) | |
(initialize-amb-fail) | |
(define (set-amb-fail! x) | |
(set! amb-fail x)) | |
(define-syntax (amb stx) | |
(syntax-case stx () | |
[(_ alts ...) | |
#`(let ((+prev-amb-fail amb-fail)) | |
(call/cc | |
(lambda (+sk) | |
#,@(map (lambda (alt) | |
#`(call/cc | |
(lambda (+fk) | |
(set-amb-fail! | |
(lambda () | |
(set-amb-fail! +prev-amb-fail) | |
(+fk 'fail))) | |
(+sk #,alt)))) | |
(syntax->list #'(alts ...))) | |
(+prev-amb-fail))))]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment