O'Reilly logo

Learning GNU Emacs, 3rd Edition by Bill Rosenblatt, Eric S. Raymond, Marc Loy, James Elliott, Debra Cameron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lisp Primitive Functions

Now that you’ve seen how to write a working command, we’ll discuss Lisp’s primitive functions. These are the building blocks from which you’ll build your functions. As mentioned above, Lisp uses functions where other languages would use operators, that is, for arithmetic, comparison, and logic. Table 11-3 shows some Lisp primitive functions that are equivalent to these operators.

Table 11-3. 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 for example, (/ 7.0 4) returns 1.75, and (/ 7 4) returns 1. 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’s 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 and save-excursion include statement blocks. Other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required