For Gauche 0.9.11Search (procedure/syntax/module):

Next: , Previous: , Up: Core syntax   [Contents][Index]

4.11 Inclusions

Special Form: include filename …
Special Form: include-ci filename …

[R7RS base] Reads filename … at compile-time, and insert their contents as if the forms are placed in the includer’s source file, surrounded by begin. The 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 include 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 ./ or ../—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 in 0.9.5.)

Gauche has other means to incorporate source code from another files. Here’s the comparison.

require (use and extend calls require internally)
load

Usually, require (or use and extend) are better way to incorporate sources in other files. The include 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 include, 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"))

Next: , Previous: , Up: Core syntax   [Contents][Index]


For Gauche 0.9.11Search (procedure/syntax/module):