[plt-scheme] require with custom modules

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Sat Nov 10 16:01:25 EST 2007

On Sat, 2007-11-10 at 19:34 +0100, Cyprien Nicolas wrote:
> Hi
> I'm building an application to compile a subset of BASIC expressions
> into scheme (my Interpretation course at the University of Nice), I
> have defined several modules to handle the compilation process (lexer,
> parser, etc).
> The application is launched by a main.scm file located in the root
> directory of the app.
> The GUI is located in a gui/ dir, and the modules in the parse/ dir
> So I use (load (build-path (current-directory) "gui" "gui.scm") to
> load the GUI, and I'd like to do the same for require my modules,
> because gui.scm needs to load some of them.

Just wondering, why does "main.scm" use 'load' instead of 'require'?

> I don't want to use the form (require (file "../parse/parser.ss"))
> because I hate using .. in file paths, and depending on where the
> require is made, every path will be different.
> So I think using (build-path ) could be a cleaner way, after defining
> every dir in the main.scm
> For example, the path to the lexer will be (build-path
> myapp-modules-directory "lexer.ss").

Based on your description of the organization of your modules, ".." is
the right solution. You don't need the 'file' part, though:

  (require "../parse/parser.ss")

Then, if you move your project directory to a new place, the relative
module path still works. If you send your code to a friend, it still
works. If you turn it into a PLaneT package, it still works. If you
reorganize your project directories, you'll have to update them, but
that shouldn't happen often, and it's easy to update anyway.

Do you have a particular reason for disliking ".." in module paths? It
really is standard for internal references within a body of code.

> However, the require special form doesn't evaluate its arguments,
> neither (require (build-path some-dir some-file)) nor (require (file
> (build-path some-dir some-file))) works.
> I look at require in the PLT Help Desk and I didn't find a way to do this.
> I also looked for a way to add my app/parse path to the require
> default path, but the only thing I found is to use
> (current-library-collection-paths) is order to cons a new path into
> this list and to use (require (lib ...)), and then to add a collects
> dir into my project.
> I don't think that is the good way to resolve my problem because my
> modules are specific to the application and there are *not really*
> library files.
> So, Is using current-library-collection-paths the good way to do this ?

Don't use 'current-library-collection-paths'. It isn't the right


Posted on the users mailing list.