Here are some tips for making compiled code run fast:
(defun scan-list (list elt)
"Search the LIST for an element ELT. Return it if one is found."
(if (eq (car list) elt)
elt
(scan-list (cdr list) elt)))
but this is fairly slow. Instead, iterate through each element,
(defun scan-list (list elt)
(while (consp list)
(when (eq (car list) elt)
(return elt))
(setq list (cdr list))))
member, memq, assoc,
etc... can be used to search lists. Since these are primitives written
in C they will run much faster than an equivalent Lisp function.
So the above scan-list example can be rewritten as,
(defun scan-list (list elt) (car (memq elt list)))Also note that the
mapcar and mapc functions are useful
(and efficient) when using lists.
when and unless conditional
structures; they are more efficient than cond or if.
eq whereas two references to the same variable are always
eq).
cons, car, cdr, rplaca, rplacd, nth,
nthcdr, aset, aref, length, eval, +,
*, /, %, lognot, not, logior,
logand, equal, eq, =, /=, >,
<, >=, <=, 1+, 1-, -, set,
fset, lsh, zerop, null, atom, consp,
listp, numberp, stringp, vectorp, throw,
fboundp, boundp, symbolp, get, put,
signal, return, reverse, nreverse, assoc,
assq, rassoc, rassq, last, mapcar, mapc,
member, memq, delete, delq, delete-if,
delete-if-not, copy-sequence, sequencep, functionp,
special-formp, subrp, eql, set-current-buffer,
current-buffer, bufferp, markp, windowp.
require function are evaluated then the unevaluated form
is written as-is to the output file. The reason it is evaluated is so that
any macros defined in the required module are loaded before they are
called by the program being compiled.
if, cond, when, unless, let, let*,
catch, unwind-protect, error-protect, with-buffer,
with-window, progn, prog1, prog2, while,
and, or.
then the form is compiled. Otherwise it is just written to the output file
in its uncompiled state.
progn
block to make the compiler coalesce them into one byte-code form.
Go to the first, previous, next, last section, table of contents.