Peter Siebel - Practical Common Lisp
Здесь есть возможность читать онлайн «Peter Siebel - Practical Common Lisp» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Год выпуска: 2005, ISBN: 2005, Издательство: Apress, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Practical Common Lisp
- Автор:
- Издательство:Apress
- Жанр:
- Год:2005
- ISBN:1-59059-239-5
- Рейтинг книги:4 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 80
- 1
- 2
- 3
- 4
- 5
Practical Common Lisp: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Practical Common Lisp»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Practical Common Lisp — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Practical Common Lisp», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
(= 1 1) ==> T
(= 10 20/2) ==> T
(= 1 1.0 #c(1.0 0.0) #c(1 0)) ==> T
The /=
function, conversely, returns true only if all its arguments are different values.
(/= 1 1) ==> NIL
(/= 1 2) ==> T
(/= 1 2 3) ==> T
(/= 1 2 3 1) ==> NIL
(/= 1 2 3 1.0) ==> NIL
The functions <
, >
, <=
, and >=
order rationals and floating-point numbers (in other words, the real numbers.) Like =
and /=
, these functions can be called with more than two arguments, in which case each argument is compared to the argument to its right.
(< 2 3) ==> T
(> 2 3) ==> NIL
(> 3 2) ==> T
(< 2 3 4) ==> T
(< 2 3 3) ==> NIL
(<= 2 3 3) ==> T
(<= 2 3 3 4) ==> T
(<= 2 3 4 3) ==> NIL
To pick out the smallest or largest of several numbers, you can use the function MIN
or MAX
, which takes any number of real number arguments and returns the minimum or maximum value.
(max 10 11) ==> 11
(min -12 -10) ==> -12
(max -1 2 -3) ==> 2
Some other handy functions are ZEROP
, MINUSP
, and PLUSP
, which test whether a single real number is equal to, less than, or greater than zero. Two other predicates, EVENP
and ODDP
, test whether a single integer argument is even or odd. The P suffix on the names of these functions is a standard naming convention for predicate functions, functions that test some condition and return a boolean.
Higher Math
The functions you've seen so far are the beginning of the built-in mathematical functions. Lisp also supports logarithms: LOG
; exponentiation: EXP
and EXPT
; the basic trigonometric functions: SIN
, COS
, and TAN
; their inverses: ASIN
, ACOS
, and ATAN
; hyperbolic functions: SINH
, COSH
, and TANH
; and their inverses: ASINH
, ACOSH
, and ATANH
. It also provides functions to get at the individual bits of an integer and to extract the parts of a ratio or a complex number. For a complete list, see any Common Lisp reference.
Characters
Common Lisp characters are a distinct type of object from numbers. That's as it should be—characters are not numbers, and languages that treat them as if they are tend to run into problems when character encodings change, say, from 8-bit ASCII to 21-bit Unicode. [117] Even Java, which was designed from the beginning to use Unicode characters on the theory that Unicode was the going to be the character encoding of the future, has run into trouble since Java characters are defined to be a 16-bit quantity and the Unicode 3.1 standard extended the range of the Unicode character set to require a 21-bit representation. Ooops.
Because the Common Lisp standard didn't mandate a particular representation for characters, today several Lisp implementations use Unicode as their "native" character encoding despite Unicode being only a gleam in a standards body's eye at the time Common Lisp's own standardization was being wrapped up.
The read syntax for characters objects is simple: #\
followed by the desired character. Thus, #\x
is the character x
. Any character can be used after the #\
, including otherwise special characters such as "
, (
, and whitespace. However, writing whitespace characters this way isn't very (human) readable; an alternative syntax for certain characters is #\
followed by the character's name. Exactly what names are supported depends on the character set and on the Lisp implementation, but all implementations support the names Space and Newline . Thus, you should write #\Space
instead of #\
, though the latter is technically legal. Other semistandard names (that implementations must use if the character set has the appropriate characters) are Tab , Page , Rubout , Linefeed , Return , and Backspace .
Character Comparisons
The main thing you can do with characters, other than putting them into strings (which I'll get to later in this chapter), is to compare them with other characters. Since characters aren't numbers, you can't use the numeric comparison functions, such as <
and >
. Instead, two sets of functions provide character-specific analogs to the numeric comparators; one set is case-sensitive and the other case-insensitive.
The case-sensitive analog to the numeric =
is the function CHAR=
. Like =
, CHAR=
can take any number of arguments and returns true only if they're all the same character. The case- insensitive version is CHAR-EQUAL
.
The rest of the character comparators follow this same naming scheme: the case-sensitive comparators are named by prepending the analogous numeric comparator with CHAR
; the case-insensitive versions spell out the comparator name, separated from the CHAR
with a hyphen. Note, however, that <=
and >=
are "spelled out" with the logical equivalents NOT-GREATERP
and NOT-LESSP
rather than the more verbose LESSP-OR-EQUALP
and GREATERP-OR-EQUALP
. Like their numeric counterparts, all these functions can take one or more arguments. Table 10-1 summarizes the relation between the numeric and character comparison functions.
Table 10-1. Character Comparison Functions
Numeric Analog | Case-Sensitive | Case-Insensitive |
= |
CHAR= |
CHAR-EQUAL |
/= |
CHAR/= |
CHAR-NOT-EQUAL |
< |
CHAR< |
CHAR-LESSP |
> |
CHAR> |
CHAR-GREATERP |
<= |
CHAR<= |
CHAR-NOT-GREATERP |
>= |
CHAR>= |
CHAR-NOT-LESSP |
among other things, testing whether given character is alphabetic or a digit character, testing the case of a character, obtaining a corresponding character in a different case, and translating between numeric values representing character codes and actual character objects. Again, for complete details, see your favorite Common Lisp reference.
Читать дальшеИнтервал:
Закладка:
Похожие книги на «Practical Common Lisp»
Представляем Вашему вниманию похожие книги на «Practical Common Lisp» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Practical Common Lisp» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.