From 23d5cf568ef77e50c7cb4ae517a064af0d82ba73 Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Tue, 20 May 2014 16:00:09 -0500 Subject: [PATCH] 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. --- pkgs/htdp-pkgs/htdp-lib/lang/htdp-langs.rkt | 8 ++++++-- .../htdp-lib/lang/run-teaching-program.rkt | 17 +++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkgs/htdp-pkgs/htdp-lib/lang/htdp-langs.rkt b/pkgs/htdp-pkgs/htdp-lib/lang/htdp-langs.rkt index 284e18347c..8a0a1e4bbb 100644 --- a/pkgs/htdp-pkgs/htdp-lib/lang/htdp-langs.rkt +++ b/pkgs/htdp-pkgs/htdp-lib/lang/htdp-langs.rkt @@ -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 diff --git a/pkgs/htdp-pkgs/htdp-lib/lang/run-teaching-program.rkt b/pkgs/htdp-pkgs/htdp-lib/lang/run-teaching-program.rkt index 0771e80fd9..2f5f330676 100644 --- a/pkgs/htdp-pkgs/htdp-lib/lang/run-teaching-program.rkt +++ b/pkgs/htdp-pkgs/htdp-lib/lang/run-teaching-program.rkt @@ -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