clean up initialization of the teachpacks in an empty repl

In more detail, the way the initial namespace was being set up was
different than the way that you get if you just hit 'Run' on an
empty program. So change the initial namespace creation to more closely
mimic the way an running an empty program works.
This commit is contained in:
Robby Findler 2014-05-20 16:00:09 -05:00
parent a57e712ba3
commit 23d5cf568e
2 changed files with 17 additions and 8 deletions

View File

@ -468,8 +468,12 @@
(newline port)))
(define/override (first-opened settings)
(for ([tp (in-list (htdp-lang-settings-teachpacks settings))])
(namespace-require/constant tp)))
(define-values (mod name)
(create-empty-module (get-module)
(htdp-lang-settings-teachpacks settings)))
(eval mod)
(dynamic-require `',name #f)
(current-namespace (module->namespace `',name)))
(define/private (tp-require->str tp)
(match tp

View File

@ -11,6 +11,7 @@
(only-in racket/sequence sequence->list))
(provide/contract
[create-empty-module (->* (any/c (listof any/c)) (symbol?) (values any/c symbol?))]
[expand-teaching-program (->* (input-port?
(-> any/c input-port? any/c)
any/c
@ -27,6 +28,15 @@
;; a require. The module includes a 'require' for each teachpack that
;; the user has added. Also, any 'provide' expressions are stripped out.
(define (create-empty-module language-module teachpacks [module-name '#%htdp])
(values (datum->syntax
#f
`(,#'module ,module-name ,language-module
,@(map (λ (x)
`(require ,x))
teachpacks)))
module-name))
(define (expand-teaching-program port reader language-module teachpacks [module-name '#%htdp] [enable-testing? #t])
(define state 'init)
;; state : 'init => 'require => 'done-or-exn
@ -43,12 +53,7 @@
(λ (x)
(set! saved-exn x)
(expand
(datum->syntax
#f
`(,#'module ,module-name ,language-module
,@(map (λ (x)
`(require ,x))
teachpacks)))))])
(create-empty-module language-module teachpacks module-name)))])
(define body-exps (suck-all-exps port reader))
(define teachpack-requires (teachpacks->requires teachpacks))
(rewrite-module