# Module and namespace: how to use module-\>namespace

**URL:** <https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881>\
**Category:** Questions & Answers\
**Created:** [July 29, 2025, 9:48am UTC](https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881 "2025-07-29T09:48:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lylgithub2021](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/lylgithub2021/32/2392_2.png) [@lylgithub2021](https://racket.discourse.group/u/lylgithub2021)\
**Post date:** [July 29, 2025, 9:48am UTC](https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881/1 "2025-07-29T09:48:09Z")

</div>

#lang racket

(module m racket/base

(provide x)

(define x 11))

(require 'm)

(define ns (module-\>namespace ''m))

(eval 'x ns)

error meassage is given when running the above code:

module-\>namespace: unknown module in the current namespace

name: #resolved-module-path:'m

Why?

---

<div class="post-metadata">

**Author:** ![gus-massa](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/gus-massa/32/507_2.png) [@gus-massa](https://racket.discourse.group/u/gus-massa)\
**Post date:** [July 29, 2025, 1:56pm UTC](https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881/2 "2025-07-29T13:56:24Z")

</div>

Just the formatted code with 4 spaces, no solution:

```scheme
#lang racket
(module m racket/base
  (provide x)
  (define x 11))
(require 'm)
(define ns (module->namespace ''m))
(eval 'x ns)

```

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [July 30, 2025, 12:20pm UTC](https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881/3 "2025-07-30T12:20:51Z")

</div>

1. I think you need to `namespace-require` the module path prior to using `module->namespace`.
2. `module->namespace` needs a module path that is a path like `"file.rkt"` — or, if you want it to work on a submodule `m`, you need to use `(submod "file.rkt" m)`.
3. You may need to `namespace-syntax-introduce` the expression given to `eval`, much like `read-eval-print-loop` does. (Keep in mind that `module->namespace` is intended to support getting a REPL “inside” a module, AFICT. It’s not something you’d likely use in the vast majority of “normal” Racket programs.)

So for example if `file.rkt` is:

```scheme
#lang racket/base
(define x 42)

```

Then your `example.rkt` could be:

```scheme
#lang racket/base

(define mod "file.rkt")
(namespace-require mod)
(parameterize ([current-namespace (module->namespace mod)])
  (eval (namespace-syntax-introduce #'x)))

```

If you wanted to do this to a submodule in the same `example.rkt`, then `example.rkt` could be:

```scheme
#lang racket/base

(module m racket/base
  (define x 42))

(define mod '(submod "example.rkt" m))
(namespace-require mod)
(parameterize ([current-namespace (module->namespace mod)])
  (eval (namespace-syntax-introduce #'x)))

```

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [July 30, 2025, 12:39pm UTC](https://racket.discourse.group/t/module-and-namespace-how-to-use-module-namespace/3881/4 "2025-07-30T12:39:53Z")

</div>

p.s. I got distracted by the new Discourse auto-formatting features while typing this, and ended up going back and editing my post many times. So if you’re reading this only via email, it’s quite different from what ended up on this web site – sorry!
