Книга: Learning GNU Emacs, 3rd Edition

11.2 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.

Оглавление книги

Оглавление статьи/книги

Генерация: 1.179. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз