Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Common Lisp: Does `load` do `compile-file` things?

Suppose I have a file named "includes.cl", inside which there are several function definitions. Now I have two ways to use these functions:

  1. (load "includes.cl")
  2. (load (compile-file "includes.cl"))

Is the latter faster than the former? I only concern the runtime speed of function invoking.

like image 404
SaltyEgg Avatar asked Sep 08 '13 02:09

SaltyEgg


People also ask

Is Common Lisp compiled?

Lisp is a compiled general purpose language, in its modern use. To clarify: “LISP” is nowadays understood as “Common Lisp” Common Lisp is an ANSI Standard.

How do I load a file in Lisp?

To load an Emacs Lisp file, type M-x load-file . This command reads a file name using the minibuffer, and executes the contents of that file as Emacs Lisp code. It is not necessary to visit the file first; this command reads the file directly from disk, not from an existing Emacs buffer.


1 Answers

To answer the question you ask, there is no way to say a priori which of your two forms is faster. However, your second form will probably result in the functions and macros found in "includes.cl" being executed faster.

More to the point though, just like you would not recompile a C library every time you link something against it, you should not recompile a Lisp library before every load.

At the very least you should be using something like load-compile-maybe or a Lisp analogue of make, such as asdf.

EDIT: you are using SBCL which does not have an interpreter, only a compiler. This means that all code is compiled before is it executed, so the two forms in your question are equivalent. However, the bulk of the cost is in compile-file, not in load, so it is a very good idea to compile the file once and then load it using (load "includes") (note the lack of file type, AKA, extension).

like image 167
sds Avatar answered Sep 22 '22 01:09

sds