Книга: 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.
- Chapter 11. Emacs Lisp Programming
- CHAPTER 4 Functions and Libraries in mikroC
- 14.4.8. Emacs Lisp
- Functions
- Basic Functions
- Using Functions in Shell Scripts
- 4.1 mikroC Functions
- 4.2 mikroC Built-in Functions
- 4.3 mikroC Library Functions
- 4.1.2 Passing Arrays to Functions
- 4.1.3 Passing Variables by Reference to Functions
- 7.2 mikroC Language SD Card Library Functions