# Send to REPL and multi-module projects

**URL:** https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146
**Category:** Questions & Answers
**Tags:** question, emacs
**Created:** [March 16, 2026, 5:20am UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146 "2026-03-16T05:20:36Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![alexsh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexsh/32/2598_2.png) [@alexsh](https://racket.discourse.group/u/alexsh)
#### Post date: [March 16, 2026, 5:20am UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/1 "2026-03-16T05:20:36Z")

</div>

Originally asked here: [Send to REPL and multi-module projects · Issue #766 · greghendershott/racket-mode · GitHub](https://github.com/greghendershott/racket-mode/issues/766)

Hi!

I am starting a project where I will have many module files, but it seems that "send to REPL" functions are not module-aware, or am I just missing some detail?

Given the following two files:

`mod1.rkt`:

```racket
#lang racket/base

(require "./mod2.rkt")

(define t 1)

```

and `mod2.rkt`:

```racket
#lang racket/base

(define t 2)

```

I do `racket-run` while visiting `mod1.rkt`. Then I visit `mod2.rkt` and try to send the definition of `t` with `racket-send-definition`. It does succeed, but overrides the `t` from `mod1`.

I need to be able to re-define in a module-aware manner (i.e. the way it works in CIDER for Clojure).

Ultimately I'm aiming to develop a video game, and hot-reloading is critical for faster feedback loop, because it eliminates the need for re-starting the game and navigating to the place I was editing (restoring the internal state).

The single-module workflow seems to satisfy my needs, but there is no way to fit the whole game in a single module/file. Re-running the module seems to discard the state, which is not what I need...

Any pointers greatly appreciated! 🙂

---

<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: [March 16, 2026, 12:58pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/2 "2026-03-16T12:58:25Z")

</div>

Thanks for posting here -- I think you'll get better advice and explanations!

For example, I was going to reply something like: "If I were developing a game in Racket, I would start by figuring out how to persist game state -- which I'd eventually expose to players as a feature -- and that use from the start to develop, do unit tests, do perf tests, etc."

But. You should probably listen to people who have actual game development experience, not me. 😄

p.s. Maybe relevant: [racket-reloadable](https://git.leastfixedpoint.com/tonyg/racket-reloadable).

p.p.s. Whatever workflow you decide on, as long as Racket supports it cleanly, I'm still glad to look at how Racket Mode could better support that workflow.

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 16, 2026, 1:57pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/3 "2026-03-16T13:57:48Z")

</div>

> [@alexsh](#):
>
> I need to be able to re-define in a module-aware manner (i.e. the way it works in CIDER for Clojure).

Can you elaborate for us that don't know CIDER nor Clojure?

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 16, 2026, 1:59pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/4 "2026-03-16T13:59:34Z")

</div>

In case you don't find anything better:

> [@Image-Based development and Interactive Experience](https://racket.discourse.group/t/image-based-development-and-interactive-experience/3679/18):
>
> @ungsams Is there something that allows to recompile just specific parts of the code without re-compiling everything? Here is a proof-of-concept. Put the following in a file "defun.rkt". Whenever you expect you will need to redefine a function, use defun instead of define. Then in the repl, you can use defun to redefine the function. Other functions referring to the function will pick up the new definition. defun.rkt #lang racket (provide defun) (define globals (make-hasheq)) (defin…

---

<div class="post-metadata">

### Author: ![alexsh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexsh/32/2598_2.png) [@alexsh](https://racket.discourse.group/u/alexsh)
#### Post date: [March 16, 2026, 2:56pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/5 "2026-03-16T14:56:34Z")

</div>

> [@soegaard](#):
>
> Can you elaborate for us that don't know CIDER nor Clojure?

Sure. Clojure is a Lisp hosted on JVM (and other runtimes). CIDER is a Emacs package that provides integration with Clojure in a similar fashion to what `racket-mode` does. It also starts a REPL with which you can interact either directly from a buffer, or by sending expressions to it.

The difference is in how namespaces/modules are treated. In CIDER if I am visiting a certain file (and thus, Clojure namespace, as there is 1:1 correspondence), sending a form or expression to the currently active REPL session is namespace-aware, such that it affects the definition in that namespace.

This is what I expected from `racket-mode`, but it doesn't seem to work that way. Instead, the currently active module gets the definition updated, not the one I am visiting.

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 16, 2026, 4:33pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/6 "2026-03-16T16:33:14Z")

</div>

Racket modules are by design more static.  
It allows better optimization (inlining for one).  
However, all the bits and pieces are there to built a more dynamic approach.  
All it takes is a bit of indirection.

You can do something like, what I linked to.  
Or you can use Racket `namespaces` to store the functions you need to redefine.  
Using your own versions of #%top and #%app you can make this seamless.

The other option is the one mentioned by Greg.  
Figure out a way to make game state persistent.  
If the repl in, say, racket-mode keeps an namespace for redefinitions untouched  
then modules can store the game state outside the module  
(whose state disappears when the module is reevaluated).

---

<div class="post-metadata">

### Author: ![alexsh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexsh/32/2598_2.png) [@alexsh](https://racket.discourse.group/u/alexsh)
#### Post date: [March 16, 2026, 7:58pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/7 "2026-03-16T19:58:22Z")

</div>

Thanks for the suggestions so far, everyone — I will definitely have a look and give them a try!

I think I owe you a slightly longer explanation of what I meant by "state" or "game state". Certainly, I am going to need to implement persistence of the game state the player cares about, such as their actual game progress, that should be able to survive restarting the game.

For now, however, I am only working on the UI framework and this is where being able to reload just the bits I actually changed is crucial for rapid development. For example, this UI features dialog windows that may pop from one another up to 5 levels deep or more. Without proper reloading, I have to go through the whole sequence of opening these windows one after another for any small adjustment I make in the code of the deepest-nested one to finally see the effects of said changes.

I actually started prototyping this game (engine) in Python, but I've outgrown its limited reloading capabilities rather quickly and was continuing purely by inertia up until now... I can share the link to the project, if there is interest and it's not against the rules here. 😉

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 16, 2026, 8:13pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/8 "2026-03-16T20:13:52Z")

</div>

To get a prebuilt solution, I think the best bet is `racket-reloadable`,  
which Greg linked to. I think, the main use case is long running servers,  
but it might fit your use case too?

[racket-reloadable](https://git.leastfixedpoint.com/tonyg/racket-reloadable)

And do link to the game.

---

<div class="post-metadata">

### Author: ![alexsh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexsh/32/2598_2.png) [@alexsh](https://racket.discourse.group/u/alexsh)
#### Post date: [March 16, 2026, 8:36pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/9 "2026-03-16T20:36:13Z")

</div>

Video games seem to pop up quite often in the discussions around the hot-patching style of development. While I do appreciate the dangers of such style and I understand why Racket deliberately decided not to support it directly, I think some contained version thereof may be attainable and hope it will fulfill my needs for this project at least. 🙂

Here's the link (as I mentioned, it is still in Python, but I am starting re-implementing it in Racket as we are talking): [GitHub - a1exsh/fhomm: Reimplementation of the game engine for "Heroes of Might and Magic" · GitHub](https://github.com/a1exsh/fhomm)

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 16, 2026, 10:26pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/10 "2026-03-16T22:26:04Z")

</div>

This looks like a fun project.

---

<div class="post-metadata">

### Author: ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)
#### Post date: [March 17, 2026, 12:54am UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/11 "2026-03-17T00:54:02Z")

</div>

> Someone replied to a topic you are Watching.
> 
> > ![](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexsh/45/2598_2.png "alexsh") | [alexsh](https://racket.discourse.group/u/alexsh)  
> > March 16 |
> > 
> > - | - |
> 
> Originally asked here: [Send to REPL and multi-module projects · Issue #766 · greghendershott/racket-mode · GitHub](https://github.com/greghendershott/racket-mode/issues/766)
> 
> Hi!
> 
> I am starting a project where I will have many module files, but it seems that "send to REPL" functions are not module-aware, or am I just missing some detail?
> 
> Given the following two files:
> 
> `mod1.rkt`:
> 
> ```scheme
> #lang racket/base
> 
> (require "./mod2.rkt")
> 
> (define t 1)
> 
> ```
> 
> and `mod2.rkt`:
> 
> ```scheme
> #lang racket/base
> 
> (define t 2)
> 
> ```
> 
> I do `racket-run` while visiting `mod1.rkt`. Then I visit `mod2.rkt` and try to send the definition of `t` with `racket-send-definition`. It does succeed, but overrides the `t` from `mod1`.

I'm not sure if this was addressed already, but Racket's REPL (assuming you sent the `define` lines) is one big "hopeless" namespace. It certainly supports modules, but the way that typically works is via `require`. You can use `,require-reloadable` at a REPL to setup a reloadable module, but some things might not work well (_e.g._, changes to a `struct` will probably not work).

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 17, 2026, 11:22am UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/12 "2026-03-17T11:22:40Z")

</div>

Ben points out something important here.

In Racket structures are generative as default.  
Each time `(struct foo (bar baz))` is evaluated, you get definitions for a new `foo` structure,  
not compatible with earlier created `foo` structures.

So, if you want "reloadable" structs, you need to add `#:prefab` to your structure definitions.

---

<div class="post-metadata">

### Author: ![hendrikboom3](https://avatars.discourse-cdn.com/v4/letter/h/b5e925/32.png) [@hendrikboom3](https://racket.discourse.group/u/hendrikboom3)
#### Post date: [March 17, 2026, 1:35pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/13 "2026-03-17T13:35:07Z")

</div>

what about letting the functions in the game code all be  
stuffed away as variabes, updated by set! operations.

Then if you need to change a funvtion while debugging,  
you just use set! to replace the entire function with a  
new one.

Of course then you still have to keep a copy of the modified  
functions in a file outside of racket so you will still have  
the changes when restarting racket from scratch.

You could even make your own variation on the define macro  
to create this log automatically.

---

<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: [March 17, 2026, 1:51pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/14 "2026-03-17T13:51:09Z")

</div>

> [@soegaard](#):
>
> So, if you want "reloadable" structs, you need to add `#:prefab` to your structure definitions.

Are `class`es also generative?

IIUC @alexsh uses `racket/gui` classes.

AFAIK we can't add `#:prefab` to third party `struct`s, and, `class` doesn't even support `#:prefab`? 😕

---

<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: [March 17, 2026, 2:06pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/15 "2026-03-17T14:06:33Z")

</div>

> [@alexsh](#):
>
> For now, however, I am only working on the UI framework and this is where being able to reload just the bits I actually changed is crucial for rapid development. For example, this UI features dialog windows that may pop from one another up to 5 levels deep or more. Without proper reloading, I have to go through the whole sequence of opening these windows one after another for any small adjustment I make in the code of the deepest-nested one to finally see the effects of said changes.

I have an idea for this specific example.

A quick preface, in general:

The REPL is a great way to "exercise" functions by calling them. After I write some function, I might use the REPL to call it with various values. (I might even copy some of those example calls into unit tests.)

There's value in making the program consist of smaller functions, that are, well, functional -- try to avoid mutating global variables, and, can be called independently.

Applying that to your example:

I think I'd define functions to handle each of the five dialogs. That way, if I were developing the dialog that's normally called nested five deep: I could make my changes in the source file buffer, `racket-run`, and in the resulting REPL, I could call that function for the 5th dialog. Skip right to it.

(If that dialog depends on values from parent dialogs, hopefully it would be reasonably convenient to pass them explicitly into that function, as opposed to grabbing them from ambient global variables.)

(If the call were annoying to keep typing in the REPL, I might temporarily have it in the body of the file that I keep running... and just hopefully remember to remove that before `git commit`-ing 😄.)

---

<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: [March 17, 2026, 2:31pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/16 "2026-03-17T14:31:50Z")

</div>

OT:

> [@greghendershott](#):
>
> The REPL is a great way to "exercise" functions by calling them. After I write some function, I might use the REPL to call it with various values. (I might even copy some of those example calls into unit tests.)

It's occurring to me now that, although the "send from edit buffer to REPL" command is convenient -- and a lispy tradition -- more often I do... the opposite. 😄

- Copy this example function call into a unit test.
- Copy this result value into a unit test (to use as the "expected" value).
- Copy this expression I worked out through trial and error in the REPL, to be a sub-expression in my edit buffer.

(Probably such a command would work best when done from some edit buffer, and "suck in" the input and/or output for the last REPL prompt. Something like that? (Heck unlike send-to-repl @EmEf might even support such a command in Dr Racket. 😮))

---

<div class="post-metadata">

### Author: ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)
#### Post date: [March 17, 2026, 3:13pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/17 "2026-03-17T15:13:16Z")

</div>

> [@greghendershott](#):
>
> Are `class`es also generative?

Haven't checked, but since they are built on top of structs, they must be.

---

<div class="post-metadata">

### Author: ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)
#### Post date: [March 17, 2026, 10:14pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/18 "2026-03-17T22:14:17Z")

</div>

@greghendershott writes "Ialthough the "send from edit buffer to REPL" command is convenient -- and a lispy tradition -- more often I do... the opposite."

A long time ago (20 years) Eli Barzilay (@elibarzilay ) proposed something just like that to me. He observed himself and students writing tests by interacting with (simple) functions in the real and then creating them. So why not have a copy-and-paste-into-tests command in Emacs? For all I know Eli hacked this into his Emacs set-up. (Of course this defeats the purpose of "work through examples before you design a function" but hey, there's good behavior and human behavior.)

---

<div class="post-metadata">

### Author: ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)
#### Post date: [March 17, 2026, 10:32pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/19 "2026-03-17T22:32:06Z")

</div>

```scheme
#lang racket

(define (make-c%)
  (class object% (super-new)))

(define-values (a% b%)
  (values (make-c%) (make-c%)))

(equal? a% b%)

```

---

<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: [March 17, 2026, 10:32pm UTC](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146/20 "2026-03-17T22:32:33Z")

</div>

> [@EmEf](#):
>
> A long time ago (20 years) Eli Barzilay (@elibarzilay ) proposed something just like that to me.

Well dang. Clearly we need [Lorites](https://anathem.fandom.com/wiki/Lorite) in real life. Not just in [_Anathem_](https://en.wikipedia.org/wiki/Anathem).

[Next page](https://racket.discourse.group/t/send-to-repl-and-multi-module-projects/4146.md?page=2)
