After the rules of syntax and semantics, the three most basic components of all Lisp programs are functions, variables and macros. You used all three while building the database in Chapter 3, but I glossed over a lot of the details of how they work and how to best use them.
A D V E R T I S E M E N T
I'll devote the next few chapters to these three topics, starting with functions, which--like their counterparts in other languages--provide the basic mechanism for abstracting, well, functionality.
Normally functions are defined using the DEFUN macro. The basic skeleton of a DEFUN looks like this:
(defun name (parameter*)
"Optional documentation string."
Any symbol can be used as a function name.2 Usually function names contain only alphabetic characters and hyphens, but other characters are allowed and are used in certain naming conventions. For instance, functions that convert one kind of value to another sometimes use -> in the name. For example, a function to convert strings to widgets might be called string->widget. The most important naming convention is the one mentioned in Chapter 2, which is that you construct compound names with hyphens rather than underscores or inner caps. Thus, frob-widget is better Lisp style than either frob_widget or frobWidget.
USER(2): (defun double (x) (* x 2))
In the above, we define a function named double, which returns two
times the value of its input argument x. We can then test-drive the
function as below: