Peter Siebel - Practical Common Lisp

Здесь есть возможность читать онлайн «Peter Siebel - Practical Common Lisp» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Год выпуска: 2005, ISBN: 2005, Издательство: Apress, Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Practical Common Lisp: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Practical Common Lisp»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Practical Common Lisp — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Practical Common Lisp», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

(count char string) ===

(count-if #'(lambda (c) (eql char c)) string)

(count char string :test #'CHAR-EQUAL) ===

(count-if #'(lambda (c) (char-equal char c)) string)

127

If you tell CONCATENATE to return a specialized vector, such as a string, all the elements of the argument sequences must be instances of the vector's element type.

128

When the sequence passed to the sorting functions is a vector, the "destruction" is actually guaranteed to entail permuting the elements in place, so you could get away without saving the returned value. However, it's good style to always do something with the return value since the sorting functions can modify lists in much more arbitrary ways.

129

By an accident of history, the order of arguments to GETHASH is the opposite of ELTELT takes the collection first and then the index while GETHASH takes the key first and then the collection.

130

LOOP 's hash table iteration is typically implemented on top of a more primitive form, WITH-HASH-TABLE-ITERATOR , that you don't need to worry about; it was added to the language specifically to support implementing things such as LOOP and is of little use unless you need to write completely new control constructs for iterating over hash tables.

131

Adapted from The Matrix ( http://us.imdb.com/Quotes?0133093)

132

CONS was originally short for the verb construct .

133

When the place given to SETF is a CAR or CDR , it expands into a call to the function RPLACA or RPLACD ; some old-school Lispers—the same ones who still use SETQ —will still use RPLACA and RPLACD directly, but modern style is to use SETF of CAR or CDR .

134

Typically, simple objects such as numbers are drawn within the appropriate box, and more complex objects will be drawn outside the box with an arrow from the box indicating the reference. This actually corresponds well with how many Common Lisp implementations work—although all objects are conceptually stored by reference, certain simple immutable objects can be stored directly in a cons cell.

135

The phrase for-side-effect is used in the language standard, but recycling is my own invention; most Lisp literature simply uses the term destructive for both kinds of operations, leading to the confusion I'm trying to dispel.

136

The string functions NSTRING-CAPITALIZE , NSTRING-DOWNCASE , and NSTRING-UPCASE are similar—they return the same results as their N-less counterparts but are specified to modify their string argument in place.

137

For example, in an examination of all uses of recycling functions in the Common Lisp Open Code Collection (CLOCC), a diverse set of libraries written by various authors, instances of the PUSH / NREVERSE idiom accounted for nearly half of all uses of recycling functions.

138

There are, of course, other ways to do this same thing. The extended LOOP macro, for instance, makes it particularly easy and likely generates code that's even more efficient than the PUSH / NREVERSE version.

139

This idiom accounts for 30 percent of uses of recycling in the CLOCC code base.

140

SORT and STABLE-SORT can be used as for-side-effect operations on vectors, but since they still return the sorted vector, you should ignore that fact and use them for return values for the sake of consistency.

141

NTH is roughly equivalent to the sequence function ELT but works only with lists. Also, confusingly, NTH takes the index as the first argument, the opposite of ELT . Another difference is that ELT will signal an error if you try to access an element at an index greater than or equal to the length of the list, but NTH will return NIL .

142

In particular, they used to be used to extract the various parts of expressions passed to macros before the invention of destructuring parameter lists. For example, you could take apart the following expression:

(when (> x 10) (print x))

Like this:

;; the condition

(cadr '(when (> x 10) (print x))) ==> (> X 10)

;; the body, as a list

(cddr '(when (> x 10) (print x))) ==> ((PRINT X))

143

Thus, MAPLIST is the more primitive of the two functions—if you had only MAPLIST , you could build MAPCAR on top of it, but you couldn't build MAPLIST on top of MAPCAR .

144

In Lisp dialects that didn't have filtering functions like REMOVE , the idiomatic way to filter a list was with MAPCAN .

(mapcan #'(lambda (x) (if (= x 10) nil (list x))) list) === (remove 10 list)

145

It's possible to build a chain of cons cells where the CDR of the last cons cell isn't NIL but some other atom. This is called a dotted list because the last cons is a dotted pair.

146

It may seem that the NSUBST family of functions can and in fact does modify the tree in place. However, there's one edge case: when the "tree" passed is, in fact, an atom, it can't be modified in place, so the result of NSUBST will be a different object than the argument: (nsubst 'x 'y 'y) X.

147

UNION takes only one element from each list, but if either list contains duplicate elements, the result may also contain duplicates.

148

It's also possible to directly SETF SYMBOL-PLIST . However, that's a bad idea, as different code may have added different properties to the symbol's plist for different reasons. If one piece of code clobbers the symbol's whole plist, it may break other code that added its own properties to the plist.

149

Macro parameter lists do support one parameter type, &environment parameters, which DESTRUCTURING-BIND doesn't. However, I didn't discuss that parameter type in Chapter 8, and you don't need to worry about it now either.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Practical Common Lisp»

Представляем Вашему вниманию похожие книги на «Practical Common Lisp» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Practical Common Lisp»

Обсуждение, отзывы о книге «Practical Common Lisp» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x