diff --git a/collects/lang/prim.rkt b/collects/lang/prim.rkt index 122f56bf9b..142ec9dc41 100644 --- a/collects/lang/prim.rkt +++ b/collects/lang/prim.rkt @@ -23,31 +23,35 @@ (with-syntax ([impl #'(let ([name (lambda argv (apply implementation argv))]) name)]) - #'(define-syntax name - (fo:make-first-order - (lambda (stx) - (with-syntax ([tagged-impl (stepper-syntax-property - (stepper-syntax-property (quote-syntax impl) 'stepper-skip-completely #t) - 'stepper-prim-name - (quote-syntax name))]) - (syntax-case stx () - [(_ . body) - ;; HACK: we disable all checks if #%app is not beginner-app - (not (module-identifier=? #'beginner-app (datum->syntax-object stx '#%app))) - (syntax/loc stx (tagged-impl . body))] - [_ - ;; HACK: see above - (not (module-identifier=? #'beginner-app (datum->syntax-object stx '#%app))) - (syntax/loc stx tagged-impl)] - [(id . args) - (syntax/loc stx (#%plain-app tagged-impl . args))] - [_ - (raise-syntax-error - #f - "expected a function call, but there is no open parenthesis before this function" - stx)]))) - ((syntax-local-certifier #t) - #'impl))))])) + #'(begin + ;; Make sure that `implementation' is bound: + (define-values () (begin implementation (values))) + ;; Bind `name': + (define-syntax name + (fo:make-first-order + (lambda (stx) + (with-syntax ([tagged-impl (stepper-syntax-property + (stepper-syntax-property (quote-syntax impl) 'stepper-skip-completely #t) + 'stepper-prim-name + (quote-syntax name))]) + (syntax-case stx () + [(_ . body) + ;; HACK: we disable all checks if #%app is not beginner-app + (not (module-identifier=? #'beginner-app (datum->syntax-object stx '#%app))) + (syntax/loc stx (tagged-impl . body))] + [_ + ;; HACK: see above + (not (module-identifier=? #'beginner-app (datum->syntax-object stx '#%app))) + (syntax/loc stx tagged-impl)] + [(id . args) + (syntax/loc stx (#%plain-app tagged-impl . args))] + [_ + (raise-syntax-error + #f + "expected a function call, but there is no open parenthesis before this function" + stx)]))) + ((syntax-local-certifier #t) + #'impl)))))])) (define-syntax (define-higher-order-primitive stx) (define (is-proc-arg? arg) diff --git a/collects/tests/htdp-lang/prim.rkt b/collects/tests/htdp-lang/prim.rkt new file mode 100644 index 0000000000..3476540d77 --- /dev/null +++ b/collects/tests/htdp-lang/prim.rkt @@ -0,0 +1,12 @@ +#lang racket/base + +(define (check-bad form) + (with-handlers ([exn:fail? (lambda (exn) + (define msg (exn-message exn)) + (unless (regexp-match #rx"unbound identifier.*y$" msg) + (raise exn)))]) + (expand form) + (error 'check-bad "failed: ~v" form))) + +(check-bad `(,#'module m racket/base (require lang/prim) (define-primitive x y))) +(check-bad `(,#'module m racket/base (require lang/prim) (provide-primitive y)))