#lang scheme/base
(require (for-syntax scheme/base)
(file "base.ss"))
(provide make-guard
define-parameter)
(define (make-guard pred type-message)
(lambda (val)
(if (pred val)
val
(raise-exn exn:fail:contract
(format "Expected ~a, received ~s" type-message val)))))
(define-syntax (define-parameter stx)
(syntax-case stx ()
[(_ id initial-value guard with-form)
#'(begin (define id
(make-parameter initial-value guard))
(define-syntax (with-form stx)
(syntax-case stx ()
[(with-form new-value exp (... ...))
#'(parameterize ([id new-value])
exp (... ...))])))]))