| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
6.17.6 Loading Scheme Code from File
- Scheme Procedure: load filename [reader]
Load filename and evaluate its contents in the top-level environment. The load paths are not searched.
reader if provided should be either
#f, or a procedure with the signature(lambda (port) …)which reads the next expression from port. If reader is#for absent, Guile’s built-inreadprocedure is used (see section Reading Scheme Code).The reader argument takes effect by setting the value of the
current-readerfluid (see below) before loading the file, and restoring its previous value when loading is complete. The Scheme code inside filename can itself change the current reader procedure on the fly by settingcurrent-readerfluid.If the variable
%load-hookis defined, it should be bound to a procedure that will be called before any code is loaded. See documentation for%load-hooklater in this section.
- Scheme Procedure: load-compiled filename
Load the compiled file named filename. The load paths are not searched.
Compiling a source file (see section Reading and Evaluating Scheme Code) and then calling
load-compiledon the resulting file is equivalent to callingloadon the source file.
- Scheme Procedure: load-from-path filename
Similar to
load, but searches for filename in the load paths. Preferentially loads a compiled version of the file, if it is available and up-to-date.
- Scheme Procedure: primitive-load filename
- C Function: scm_primitive_load (filename)
Load the file named filename and evaluate its contents in the top-level environment. The load paths are not searched; filename must either be a full pathname or be a pathname relative to the current directory. If the variable
%load-hookis defined, it should be bound to a procedure that will be called before any code is loaded. See the documentation for%load-hooklater in this section.
- C Function: SCM scm_c_primitive_load (const char *filename)
scm_primitive_load, but taking a C string instead of anSCM.
- Scheme Procedure: primitive-load-path filename [exception-on-not-found]
- C Function: scm_primitive_load_path (filename)
Search
%load-pathfor the file named filename and load it into the top-level environment. If filename is a relative pathname and is not found in the list of search paths, an error is signalled. Preferentially loads a compiled version of the file, if it is available and up-to-date.By default or if exception-on-not-found is true, an exception is raised if filename is not found. If exception-on-not-found is
#fand filename is not found, no exception is raised and#fis returned. For compatibility with Guile 1.8 and earlier, the C function takes only one argument, which can be either a string (the file name) or an argument list.
- Scheme Procedure: %search-load-path filename
- C Function: scm_sys_search_load_path (filename)
Search
%load-pathfor the file named filename, which must be readable by the current user. If filename is found in the list of paths to search or is an absolute pathname, return its full pathname. Otherwise, return#f. Filenames may have any of the optional extensions in the%load-extensionslist;%search-load-pathwill try each extension automatically.
- Variable: current-reader
current-readerholds the read procedure that is currently being used by the above loading procedures to read expressions (from the file that they are loading).current-readeris a fluid, so it has an independent value in each dynamic root and should be read and set usingfluid-refandfluid-set!(see section Fluids and Dynamic States).Changing
current-readeris typically useful to introduce local syntactic changes, such that code following thefluid-set!call is read using the newly installed reader. Thecurrent-readerchange should take place at evaluation time when the code is evaluated, or at compilation time when the code is compiled:(eval-when (compile eval) (fluid-set! current-reader my-own-reader))
The
eval-whenform above ensures that thecurrent-readerchange occurs at the right time.
- Variable: %load-hook
A procedure to be called
(%load-hook filename)whenever a file is loaded, or#ffor no such call.%load-hookis used by all of the above loading functions (load,load-path,primitive-loadandprimitive-load-path).For example an application can set this to show what’s loaded,
(set! %load-hook (lambda (filename) (format #t "Loading ~a ...\n" filename))) (load-from-path "foo.scm") -| Loading /usr/local/share/guile/site/foo.scm ...
- Scheme Procedure: current-load-port
- C Function: scm_current_load_port ()
Return the current-load-port. The load port is used internally by
primitive-load.
- Variable: %load-extensions
A list of default file extensions for files containing Scheme code.
%search-load-pathtries each of these extensions when looking for a file to load. By default,%load-extensionsis bound to the list("" ".scm").
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
