LISP Primitive Functions
Now that you’ve seen how to write a working function, we’ll discuss LISP’s primitive functions. These are the building blocks from which you’ll build your own functions. As mentioned above, LISP uses functions where other languages would use operators, that is, for arithmetic, comparison, and logic. Table 13-2 shows some LISP primitive functions that are equivalent to these operators.
Table 14-2. LISP Primitive Functions
Arithmetic |
+, -, *, / |
% (remainder) | |
1+ (increment) | |
1- (decrement) | |
max, min | |
Comparison |
>, <, >=, <= |
/= (not equal) | |
= (for numbers and characters) | |
equal (for strings and other complex objects) | |
Logic |
and, or, not |
All the arithmetic functions except 1+, 1-, and % can take arbitrarily many arguments, as can and and or. An arithmetic function returns floating point values only if at least one argument is a floating point number, so e.g., (/ 7.0 2) returns 3.5, and (/ 7 2) returns 3. Notice that integer division truncates the remainder.
It may seem inefficient or syntactically ugly to use functions for everything. However, one of the main merits of LISP is that the core of the language is small and easy to interpret efficiently. In addition, the syntax is not as much of a problem if you have support tools such as Emacs’ LISP modes to help you.
Statement Blocks
We have seen that a statement block can be defined using the let function. We also saw that while includes a statement block in its format. There are other important ...
Get Learning GNU Emacs, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.