views:

146

answers:

2

I'm going through Practical Common Lisp, I'm almost finished, and one question that has not been answered for me so far (or maybe I just missed it) is the difference between "require" and "load".

So what is the difference?

Thanks.

+5  A: 

require is used for modules, which can each consist of one or many files.

load is used to load an arbitrary single file.

The require function tests whether a module is already present (using a case-sensitive comparison); if the module is not present, require proceeds to load the appropriate file or set of files. The pathname argument, if present, is a single pathname or a list of pathnames whose files are to be loaded in order, left to right. If the pathname argument is nil or is not provided, the system will attempt to determine, in some system-dependent manner, which files to load. This will typically involve some central registry of module names and the associated file lists.

Source: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node119.html

The load function loads the file named by filename into the Lisp environment. It is assumed that a text (character file) can be automatically distinguished from an object (binary) file by some appropriate implementation-dependent means, possibly by the file type. The defaults for filename are taken from the variable default-pathname-defaults. If the filename (after the merging in of the defaults) does not explicitly specify a type, and both text and object types of the file are available in the file system, load should try to select the more appropriate file by some implementation-dependent means.

Source: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node217.html

Amber
CLTL isn't a good primary reference for CL; the HyperSpec is better. See http://l1sp.org/cl/load or http://l1sp.org/cl/require for short links to the right places.
Xach
+1  A: 

The difference is that (require) loads a module if it has not been loaded already; (load) loads a file.

kiamlaluno