(define-syntax-rule (mock (module proc replacement) body ...) "Within BODY, replace the definition of PROC from MODULE with the definition given by REPLACEMENT." (let* ((m (resolve-module 'module)) (original (module-ref m 'proc))) (dynamic-wind (lambda () (module-set! m 'proc replacement)) (lambda () body ...) (lambda () (module-set! m 'proc original)))))