use !defined for either syntax or simple binding, add !bound for a binding that cannot be a syntax

svn: r12781
This commit is contained in:
Eli Barzilay 2008-12-11 21:05:03 +00:00
parent 3e7e63aecf
commit 87e5c34935
2 changed files with 23 additions and 5 deletions

View File

@ -655,8 +655,21 @@
(define (get-namespace evaluator)
(call-in-sandbox-context evaluator (lambda () (current-namespace))))
;; checks that ids are defined, either as variables or syntaxes
(provide !defined)
(define-syntax-rule (!defined id ...)
;; expected to be used only with identifiers
(begin (with-handlers ([exn:fail:contract:variable?
(lambda (_)
(error* "missing binding: ~e" (->disp 'id)))]
[exn:fail:syntax? void])
(parameterize ([current-namespace (get-namespace (submission-eval))])
(namespace-variable-value `id)))
...))
;; checks that ids are defined as variables, not syntaxes
(provide !bound)
(define-syntax-rule (!bound id ...)
;; expected to be used only with identifiers
(begin (with-handlers ([exn:fail:contract:variable?
(lambda (_)
@ -669,6 +682,7 @@
(namespace-variable-value `id)))
...))
;; checks that ids are defined as syntaxes, not variables
(provide !syntax)
(define-syntax-rule (!syntax id ...)
;; expected to be used only with identifiers

View File

@ -327,16 +327,20 @@ code.}
@defform[(!defined id ...)]{
Checks that the given identifiers are defined in the (evaluated)
submission, and throws an error otherwise.}
submission, and throws an error otherwise. The identifiers can be
bound as either a plain value or as a syntax.}
@defform[(!procedure id arity)]{
Checks that @scheme[id] is defined, and is bound to a procedure.}
@defform[(!bound id ...)]{
Checks that the given identifiers are defined in the (evaluated)
submission as a plain value. Throws an error if not, or if an
identifier is bound to a syntax.}
@defform[(!syntax id arity)]{
Checks that @scheme[id] is defined, and is bound as a macro.}
@defform[(!procedure id arity)]{
Checks that @scheme[id] is defined, and is bound to a procedure.}
@defform[(!procedure* expr arity)]{
Similar to @scheme[!procedure] but omits the defined check, making