eval procedure directly interprets the S-expression
representation of Scheme. An alternate strategy for evaluation is to
determine ahead of time what computations will be necessary to
evaluate the expression, and then use that recipe to produce the
desired results. This is known as compilation.
While it is possible to compile simple Scheme expressions such as
(+ 2 2) or even
"Hello world!", compilation is most
interesting in the context of procedures. Compiling a lambda expression
produces a compiled procedure, which is just like a normal procedure
except typically much faster, because it can bypass the generic
Functions from system modules in a Guile installation are normally compiled already, so they load and run quickly.
Note that well-written Scheme programs will not typically call the
procedures in this section, for the same reason that it is often bad
taste to use
eval. By default, Guile automatically compiles any
files it encounters that have not been compiled yet (see
--auto-compile). The compiler can also be invoked
explicitly from the shell as
guild compile foo.scm.
(Why are calls to
compile usually in bad taste?
Because they are limited, in that they can only really make sense for
top-level expressions. Also, most needs for “compile-time”
computation are fulfilled by macros and closures. Of course one good
counterexample is the REPL itself, or any code that reads expressions
from a port.)
Automatic compilation generally works transparently, without any need
for user intervention. However Guile does not yet do proper dependency
tracking, so that if file a.scm uses macros from
b.scm, and b.scm changes,
would not be automatically recompiled. To forcibly invalidate the
auto-compilation cache, pass the
--fresh-auto-compile option to
Guile, or set the
GUILE_AUTO_COMPILE environment variable to
fresh (instead of to
For more information on the compiler itself, see Compiling to the Virtual Machine. For information on the virtual machine, see A Virtual Machine for Guile.
The command-line interface to Guile’s compiler is the
Compile file, a source file, and store bytecode in the compilation cache or in the file specified by the -o option. The following options are available:
Add dir to the front of the module load path.
Write output bytecode to ofile. By convention, bytecode file
names end in
.go. When -o is omitted, the output file
name is as for
compile-file (see below).
Recognize extension as a valid source file name extension.
For example, to compile R6RS code, you might want to pass
.sls so that files ending in .sls can be found.
Emit warnings of type warning; use
--warn=help for a list
of available warnings and their description. Currently recognized
Enable or disable specific compiler optimizations; use
a list of available options. The default is
-O2, which enables
-O1 is recommended if compilation speed is
more important than the speed of the compiled code. Pass
-Ono-opt to disable a specific compiler pass. Any number
-O options can be passed to the compiler, with later ones
Compile in an environment whose default bindings, reader options, and load paths are adapted for specific Scheme standards. See R6RS Support, and See R7RS Support.
Use lang as the source language of file. If this option is omitted,
scheme is assumed.
Use lang as the target language of file. If this option is omitted,
rtl is assumed.
Produce code for target instead of %host-type (see %host-type). Target must be a valid GNU triplet, such as
armv5tel-unknown-linux-gnueabi (see Specifying Target
Triplets in GNU Autoconf Manual).
Each file is assumed to be UTF-8-encoded, unless it contains a
coding declaration as recognized by
(see Character Encoding of Source Files).
The compiler can also be invoked directly by Scheme code using the procedures below:
Compile the expression exp in the environment env. If
exp is a procedure, the result will be a compiled procedure;
compile is mostly equivalent to
For a discussion of languages and compiler options, See Compiling to the Virtual Machine.
Compile the file named file.
Output will be written to a output-file. If you do not supply an
output file name, output is written to a file in the cache directory, as
from and to specify the source and target languages. See Compiling to the Virtual Machine, for more information on these options, and on env and opts.
guild compile, file is assumed to be
UTF-8-encoded unless it contains a coding declaration.
Compute a cached location for a compiled version of a Scheme file named file.
This file will usually be below the $HOME/.cache/guile/ccache
directory, depending on the value of the
environment variable. The intention is that
provides a fallback location for caching auto-compiled files. If you
want to place a compile file in the
should pass the output-file option to
This variable contains the options passed to the
procedure when auto-compiling source files. By default, it enables
useful compilation warnings. It can be customized from ~/.guile.