make variable-reference->namespace
enable top-level mode
The namespace returned by `variable-reference->namespace` (or `namespace-anchor->namespace`) may be used via `eval` to define new bindings, so enable top-level binding support for the namespace.
This commit is contained in:
parent
19707a54be
commit
d1c2daf15b
|
@ -1780,6 +1780,21 @@ case of module-leve bindings; it doesn't cover local bindings.
|
||||||
|
|
||||||
(test 5 dynamic-require ''module-that-exports-phase-2-x-at-phase-0 'x)
|
(test 5 dynamic-require ''module-that-exports-phase-2-x-at-phase-0 'x)
|
||||||
|
|
||||||
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Check that
|
||||||
|
;; `namespace-anchor->namespace` internally enables top-level mode for
|
||||||
|
;; binding handling:
|
||||||
|
|
||||||
|
;; Example from Alex Knauth:
|
||||||
|
(module module-that-uses-eval-to-define-a-macro-in-its-own-namespace racket/base
|
||||||
|
(require (for-syntax racket/base))
|
||||||
|
(define-namespace-anchor a)
|
||||||
|
(define ns (namespace-anchor->namespace a))
|
||||||
|
(eval '(define-syntax x (λ (stx) #'333)) ns)
|
||||||
|
(define result (eval 'x ns))
|
||||||
|
(provide result))
|
||||||
|
|
||||||
|
(test 333 dynamic-require ''module-that-uses-eval-to-define-a-macro-in-its-own-namespace 'result)
|
||||||
|
|
||||||
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
|
@ -2120,6 +2120,7 @@ static Scheme_Object *do_variable_namespace(const char *who, int tl, int argc, S
|
||||||
/* return env directly; need to set up */
|
/* return env directly; need to set up */
|
||||||
if (!env->phase && env->module)
|
if (!env->phase && env->module)
|
||||||
scheme_prep_namespace_rename(env);
|
scheme_prep_namespace_rename(env);
|
||||||
|
env->interactive_bindings = 1;
|
||||||
} else {
|
} else {
|
||||||
/* new namespace: */
|
/* new namespace: */
|
||||||
Scheme_Env *new_env;
|
Scheme_Env *new_env;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user