fix HtDP local' to work better with macros that expand to begin'

In particular, the forms within `begin' need to be partially
expanded before checking whether they're allowed.
This commit is contained in:
Matthew Flatt 2011-09-03 15:15:24 -06:00
parent 82116cc3bd
commit a53f51d92d
2 changed files with 20 additions and 8 deletions

View File

@ -1636,13 +1636,13 @@
;; forms know that it's ok to expand in this internal ;; forms know that it's ok to expand in this internal
;; definition context. ;; definition context.
[int-def-ctx (build-expand-context (make-expanding-for-intermediate-local))]) [int-def-ctx (build-expand-context (make-expanding-for-intermediate-local))])
(let* ([partly-expanded-defns (let* ([partly-expand (lambda (d)
(map (lambda (d)
(local-expand (local-expand
d d
int-def-ctx int-def-ctx
(kernel-form-identifier-list))) (kernel-form-identifier-list)))]
defns)] [partly-expanded-defns
(map partly-expand defns)]
[flattened-defns [flattened-defns
(let loop ([l partly-expanded-defns][origs defns]) (let loop ([l partly-expanded-defns][origs defns])
(apply (apply
@ -1653,7 +1653,7 @@
;; or `define-syntaxes', because only macros can generate ;; or `define-syntaxes', because only macros can generate
;; them ;; them
[(begin defn ...) [(begin defn ...)
(let ([l (syntax->list (syntax (defn ...)))]) (let ([l (map partly-expand (syntax->list (syntax (defn ...))))])
(loop l l))] (loop l l))]
[(define-values . _) [(define-values . _)
(list d)] (list d)]

View File

@ -115,3 +115,15 @@
(htdp-err/rt-test (-) (exn-type-and-msg exn:application:arity? "-: expects at least 1 argument, given 0")) (htdp-err/rt-test (-) (exn-type-and-msg exn:application:arity? "-: expects at least 1 argument, given 0"))
(htdp-err/rt-test (/) (exn-type-and-msg exn:application:arity? "/: expects at least 1 argument, given 0")) (htdp-err/rt-test (/) (exn-type-and-msg exn:application:arity? "/: expects at least 1 argument, given 0"))
;(htdp-test 1 (/ 1) exn:application:arity?) ;(htdp-test 1 (/ 1) exn:application:arity?)
;; Check that `local' works with macros that expand to `begin':
(module my-multi-defn racket/base
(provide multi)
(define-syntax-rule (multi a b)
(begin
(define a 1)
(define b 2))))
(htdp-teachpack my-multi-defn)
(htdp-test '(2 1) 'local (local [(multi x y)]
(list y x)))