
This error is easy to get: module: identifier already required
; at: foo
; in: "bar.rkt"
It usually means that we are requiring two modules that both provide a binding foo
. But which module is “the other one”? Is there a way to get that information?

syntax-sloc
has some counting tools, but could use more https://github.com/alexknauth/syntax-sloc

I don’t know of one

but adding it to the error message seems pretty reasonable; the code is here: https://github.com/racket/racket/blob/master/racket/src/expander/expand/require+provide.rkt#L321

I have a code that looks like this:
(current-compile (let ([orig-compile (current-compile)])
(lambda (stx im?)
(define compiled (orig-compile stx im?))
(when (... (syntax-source stx))
(with-output-to-file (syntax-source stx) #:exists 'replace
(thunk (display compiled))))
compiled)))
(dynamic-require ...)
This works fine on a single Racket file, but when the required file has dependencies, I get this message:
hash-ref: no value found for key
key: 'data
context...:
compiled-module->dh+h+data-instance+declaration-instance
eval-module8
standard-module-name-resolver
module-path-index-resolve
[repeats 1 more time]
module-declared?
Do you know how to fix the problem?

@mflatt @samth

file: dataset.rkt
#lang racket
(module dataset racket
(provide lorem-ipsum)
(define lorem-ipsum (list "a" "b" "c"))
)
file: main.rkt
#lang racket
(require "dataset.rkt")
lorem-ipsum

why doesn’t this work?

lorem-ipsum: unbound identifier in: lorem-ipsum

@kevinforrestconnors The lorem-ipsum
binding isn’t being provided by the dataset.rkt
module, it’s being provided by a submodule of the dataset.rkt
module. You can require it like this: (require (submod "lorem-ipsum" dataset))

Putting code inside a (module foo ...)
form in a file puts it in a submodule named foo
. The file itself is already a whole module on its own, assuming you’re using #lang racket
or #lang racket/base
.

ohh

so if I don’t want to require a submodule, I can just write: (provide lorem-ipsum)
(define lorem-ipsum
(list "Lorem ipsum dolor"))

it works!

thank you

Does anyone have an example for hsjunnesson
? He wants to embed Racket in a game. https://www.reddit.com/r/Racket/comments/dbbv6a/some_guidance_in_setting_up_racket_as_a_game/

@kevinforrestconnors happy to help!

That really looks like a bug

The relevant code is on line 359 of racket/src/expander/eval/module.rkt

Thanks! Is there any workaround meanwhile?

I don’t know what’s going on so I can’t recommend anything

I mean, what I really want to do is to perform a syntax transformation (at the core form level), and save it as a file so that I can run it later. I can’t just write (syntax->datum stx)
because the lexical context is lost and I would get unbound id when I attempt to run the file. So I try this approach instead. But if this approach doesn’t work, do you have any other idea?

I think you’re overwriting a file that contains a linklet bundle with just a single modules’ compilation, but really I’m just guessing

Hi All. Racket Stories is now live and will stay live. Hopefully everything works. Things to try: Create a user. Submit a new link. Go to your profile and link your Github.

What’s the URL?


(url? small detail…)

@sorawee The error should be better, but I think the solution is to call orig-compile
always with #f as the second argument, because you want to use the result in a way other than immediate evaluation. (Specifically, you want to write it.)

Ah, thanks!

Already creating value for me. I appreciate the Oculus and Papers We Love links, thanks!