Reads filename … at compile-time, and insert their
contents as if the forms are placed in the includer’s source file,
include form reads files
as is, while
include-ci reads files in case-insensitive
way, as if
#!fold-case is specified in the beginning of the
file (see Case-sensitivity).
The coding magic comment in each file is honored while reading that file (see Multibyte scripts).
If filename is absolute, the file is just searched. If it
is relative, the file
is first searched relative to the file containing the
form, then the directories in
*load-path* are tried.
Example: Suppose a file a.scm contains the following code:
(define x 0) (define y 1)
You can include this file into another source, like this:
(define (foo) (include "a.scm") (list x y))
It works as if the source is written as follows:
(define (foo) (begin (define x 0) (define y 1)) (list x y))
(Note: In version 0.9.4,
include behaved differently when
pathname begins with either
../—in which case
the file is searched relative to the current working directory of the
compiler. It is rather an artifact of
include sharing file
search routine with
load. But unlike
load, which is
a run-time operation, using relative path to the current directory
won’t make much sense for
include, so we changed the behavior
Gauche has other means to incorporate source code from another files. Here’s the comparison.
includework at compile-time.
Requireworks only in toplevel context, while
includecan be anywhere.
Requirereads the file only once (second and later
requireon the same file becomes no-op), while
includereads the file every place it appears.
*load-path*. The location of the file
requireform appears doesn’t matter. (You can add directories relative to the requiring file using the
select-moduleinside the required file, it is only effective while the required file is read. On the other hand,
includeinserts any S-expressions in the included file to the place
includeappears, so the effect of
includeform (Note: Encoding magic comment and
#!no-fold-caseare dealt with by the reader, so those effect is contained in the file even with
requireto insert a toplevel binding without specifying a module. In other words, the file you require should generally use
define-library. See Require and provide, for further discussion. On the other hand,
includehas no such restrictions.
includeworks at compile-time.
includecan be anywhere.
*load-path*, except when the file begins with
../, in which case it is first tried relative to the current directory before being searched from
require, change of the current module won’t persist after
better way to incorporate sources in other files. The
form is mainly for the tricks that can’t be achieved with
require. For example, you have a third-party R5RS code
and you want to wrap it with Gauche module system. Using
you place the following small source file along the third-party code,
and you can load the code with
(use third-party-module) without
changing the original code at all.
(define-module third-party-module (export proc ...) (include "third-party-source.scm"))