2
votes

In my Racket program, I get the error message: "module: identifier already required in doc" when I try to require code from a file that I've written. But when I copy and paste the code into the requiring module, it works fine. Ideas?

I've tried using (provide (all-defined-out)) as well as listing all of the functions names in the provide form. By the way, I'm coding this in Scribble files rather than straight Racket files.

@(require racket/date
          racket/file
          racket/string
          racket/list
          racket/function
          racket/format
          db
          "directories.scrbl"
          "model-files.scrbl"
          )

Note that all the imports work fine from the directories.scrbl file, but the problem happens when I require model-files.scrbl.

Update: It's definitely a problem with Scribble. I changed all the code to Racket code from Scribble and the problem disappeared.

1

1 Answers

2
votes

#lang scribble/base, #lang scribble/manual, and #lang scribble/doc automatically provide doc. Therefore, when you unconditionally require two Scribble documents, doc is collided.

There are two ways to solve this problem.

  1. Use only-in or except-in to control what should be required. For instance, you can write:

    (require (except-in "directories.scrbl" doc)
             (except-in "model-files.scrbl" doc))
    

    This would require everything from directories.scrbl and model-files.scrbl except doc from both of them.

  2. But as far as I know, it's very uncommon (and unidiomatic) to require a Scribble file directly. The better way is to restructure by creating a Racket file named utils.rkt and put the thing that you want to use in several Scribble files in utils.rkt, and then (require "utils.rkt") instead.