REQUIRE
The function REQUIRE
receives as the optional argument either
a PATHNAME
or a LIST
of PATHNAME
s: files to be LOAD
ed
if the required module is not already present.
When the module is already present, NIL
is returned;
otherwise returns the TRUENAME
which was loaded to satisfy the REQUIRE
ment
(or LIST
thereof iff the second argument is a LIST
).
LOAD
locationsIn addition to (and before) CUSTOM:*LOAD-PATHS*
, REQUIRE
tries to
find the file to LOAD
in the following locations:
Platform Dependent: Only in CLISP built without configure flag --without-dynamic-modules
.
The system-wide external modules directory
(
.MERGE-PATHNAMES
"dynmod/" CUSTOM:*LIB-DIRECTORY*
)
Platform Dependent: Only in CLISP built without configure flag --without-dynamic-modules
.
The user external modules directory (
(when MERGE-PATHNAMES
"dynmod/" CUSTOM:*USER-LIB-DIRECTORY*
)CUSTOM:*USER-LIB-DIRECTORY*
is non-NIL
).
REQUIRE
was called while LOAD
ing, the
directory with the file being loaded (i.e., (MAKE-PATHNAME
:name NIL
:type NIL
:defaults *LOAD-TRUENAME*
)
).
CUSTOM::*MODULE-PROVIDER-FUNCTIONS*
When REQUIRE
is called without the second (pathname) argument,
the elements of the CUSTOM::*MODULE-PROVIDER-FUNCTIONS*
LIST
are called one by one
on the first (module name) argument until one of them returns non-NIL
.
If all of them return NIL
, LOAD
is called as described
above.
Initially the lisp is empty; (require "
modifies it (Platform Dependent: if CLISP was configured with the
option asdf
")--with-module=asdf
).
COMPILE-FILE
At compile time, (
forms are treated specially: REQUIRE
#P"foo"
)CUSTOM:*LOAD-PATHS*
is searched for
#P"foo.lisp"
and #P"foo.lib"
.
If the latest such file is a #P".lisp"
, it is compiled;
otherwise the #P".lib"
is loaded.
If neither is found, (
is called.REQUIRE
#P"foo"
)
It is a very bad
idea to name your files the same way as CLISP modules
(whether system-supplied
or user-installed)
because then REQUIRE
will use different files at compile
and execution times.
The #P".lib"
is a “header” file which contains the
constant, variable, inline and macro definitions necessary for
compilation of the files that REQUIRE
this file, but not the function
definitions and calls that are not necessary for that.
Thus it is not necessary to either enclose REQUIRE
forms in
EVAL-WHEN
or to load the required files in the makefiles: if you have
two files, #P"foo.lisp"
and #P"bar.lisp"
, and the
latter requires the former, you can write in your Makefile
:
all: foo.fas bar.fas foo.fas: foo.lisp clisp-c
foo bar.fas: bar.lisp foo.fas clisp-c
bar
instead of the more cumbersome (and slower, since #P".lib"
s are
usually smaller and load faster that #P".fas"
s):
bar.fas: bar.lisp foo.fas clisp-i
foo-c
bar
Thus, you do not need to (
in order
to LOAD
#P"foo"
)(
.
If memory is tight, and if COMPILE-FILE
#P"bar.lisp"
)#P"foo.lisp"
contains only a few inline
functions, macros, constants or variables, this is a space and time
saver. If #P"foo.lisp"
does a lot of initializations or side effects
when being loaded, this is important as well.
These notes document CLISP version 2.49.93+ | Last modified: 2018-02-19 |