# Evaluating file at runtime in Racket

**URL:** <https://racket.discourse.group/t/evaluating-file-at-runtime-in-racket/2718>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [February 13, 2024, 2:51pm UTC](https://racket.discourse.group/t/evaluating-file-at-runtime-in-racket/2718 "2024-02-13T14:51:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/xiaoyu2006/32/1682_2.png) [@xiaoyu2006](https://racket.discourse.group/u/xiaoyu2006)\
**Post date:** [February 13, 2024, 2:51pm UTC](https://racket.discourse.group/t/evaluating-file-at-runtime-in-racket/2718/1 "2024-02-13T14:51:44Z")

</div>

This is originally a [Stack Overflow post](https://stackoverflow.com/questions/77973334/evaluating-file-at-runtime-in-racket) however issue A in the comment of the [answer](https://stackoverflow.com/a/77975103/10811334) still persists. Thanks for any help in advance!

=====Copy & Paste of the Stack Overflow Question=====

I am making an application using Racket in which Racket is also used as a scripting language. I want users to write scripts utilizing some structs and procedures provided in my executable.

For example I have `userruntime.rkt`:

```racket
(struct result (x y z))
(provide (all-from-out racket/base))
(provide (struct-out result))

```

And user writes `script.rkt`:

```racket
(define (my-even? x)
  (if (eq? x 0) #t
                (not (my-odd? (sub1 x)))))

(define (my-odd? x)
  (not (my-even? (sub1 x))))

(result (my-odd? 1) (my-odd? 2) (my-odd? 3))

```

I want to evaluate to the following result (you get the idea):

```racket
'(#<void> #<void> (result #t #f #t))

```

It seems that `make-module-evaluator` in `racket/sandbox` satisfies my needs. However I failed to find a way to pass the module (as a file compiled and linked in the final executable). The official documentation gives the following example:

```racket
(define base-module-eval
    (make-evaluator 'racket/base '(define (f) later)
                                 '(define later 5)))

```

Which is not requiring a file. When I try:

```racket
(make-module-evaluator "userruntime.rkt") ; make-module-evaluator: expecting a `module' program; got userruntime.rkt [,bt for context]
;; or
(make-module-evaluator 'userruntime) ; make-module-evaluator: expecting a `module' program; got userruntime[,bt for context]

```

How do I refer to the module in the file correctly?

---

<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:** [February 13, 2024, 4:28pm UTC](https://racket.discourse.group/t/evaluating-file-at-runtime-in-racket/2718/2 "2024-02-13T16:28:05Z")

</div>

If I understand you correctly, you would like three modules:

1. `support.rkt` to define the `result` struct once and for all
2. (possibly many) `client.rkt` modules, which are _not_ supposed to `(require “support.rkt”)` [for reasons to be clarified]
3. `combine.rkt` to link `client.rkt` with `support.rkt` retroactively.

Is that the case? If so, why can’t `client.rkt` not require the support file?

---

<div class="post-metadata">

**Author:** ![xiaoyu2006](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/xiaoyu2006/32/1682_2.png) [@xiaoyu2006](https://racket.discourse.group/u/xiaoyu2006)\
**Post date:** [March 3, 2024, 1:19pm UTC](https://racket.discourse.group/t/evaluating-file-at-runtime-in-racket/2718/3 "2024-03-03T13:19:03Z")

</div>

@EmEf Yes exactly. To be more specific, I want to treat `userruntime.rkt` or `support.rkt` as a module language. I also hope to rename and re-export some racket symbols (for example, `list` to `r:list`), thus make client.rkt some sort of DSL based on Racket.

Also to clarify, the StackOverflow answer works but only works when code is loaded dynamically. However, I hope to embed `userruntime.rkt` to the binary distribution.
