Version: 4.2.1

6.1 Module Basics

The space of module names is distinct from the space of normal Scheme definitions. Indeed, since modules typically reside in files, the space of module names is explicitly tied to the filesystem at run time. For example, if the file "/home/molly/" contains

  #lang scheme
  (provide print-cake)
  ; draws a cake with n candles
  (define (print-cake n)
    (printf "   ~a  \n" (make-string n #\.))
    (printf " .-~a-.\n" (make-string n #\|))
    (printf " | ~a |\n" (make-string n #\space))
    (printf "---~a---\n" (make-string n #\-)))

then it can be used as the source of a module whose full name is based on the path "/home/molly/". The provide line exports the definition print-cake so that it can be used outside the module.

Instead of using its full path, a module is more likely to be referenced by a relative path. For example, a file "/home/molly/" could use the "" module like this:

  #lang scheme
  (require "")
  (print-cake (random 30))

The relative reference "" in the import (require "") works because the "" module source is in the same directory as the "" file. (Unix-style relative paths are used for relative module references on all platforms, much like relative URLs.)

Library modules that are distributed with PLT Scheme are usually referenced through an unquoted, suffixless path. The path is relative to the library installation directory, which contains directories for individual library collections. The module below refers to the "" library that is part of the "scheme" collection.

  #lang scheme
  (require scheme/date)
  (printf "Today is ~s\n"
          (date->string (seconds->date (current-seconds))))

In addition to the main collection directory, which contains all collections that are part of the installation, collections can also be installed in a user-specific location. Finally, additional collection directories can be specified in configuration files or through the PLTCOLLECTS search path. Try running the following program to find out where your collections are:

  #lang scheme
  (require setup/dirs)
  (find-collects-dir) ; main collection directory
  (find-user-collects-dir) ; user-specific collection directory
  (get-collects-search-dirs) ; complete search path

We discuss more forms of module reference later in Module Paths.