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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
COMMON-LISP-USER
is also allowed to provide access to symbols exported by other implementation-defined packages. While this is intended as a convenience for the user—it makes implementation-specific functionality readily accessible—it can also cause confusion for new Lispers: Lisp will complain about an attempt to redefine some name that isn't listed in the language standard. To see what packages COMMON-LISP-USER
inherits symbols from in a particular implementation, evaluate this expression at the REPL:
(mapcar #'package-name (package-use-list :cl-user))
And to find out what package a symbol came from originally, evaluate this:
(package-name (symbol-package 'some-symbol))
with some-symbol
replaced by the symbol in question. For instance:
(package-name (symbol-package 'car)) ==> "COMMON-LISP"
(package-name (symbol-package 'foo)) ==> "COMMON-LISP-USER"
Symbols inherited from implementation-defined packages will return some other value.
224
This is different from the Java package system, which provides a namespace for classes but is also involved in Java's access control mechanism. The non-Lisp language with a package system most like Common Lisp's packages is Perl.
225
All the manipulations performed by DEFPACKAGE
can also be performed with functions that man- ipulate package objects. However, since a package generally needs to be fully defined before it can be used, those functions are rarely used. Also, DEFPACKAGE
takes care of performing all the package manipulations in the right order—for instance, DEFPACKAGE
adds symbols to the shadowing list before it tries to use the used packages.
226
In many Lisp implementations the :use
clause is optional if you want only to :use COMMON-LISP
—if it's omitted, the package will automatically inherit names from an implementation-defined list of packages that will usually include COMMON-LISP
. However, your code will be more portable if you always explicitly specify the packages you want to :use
. Those who are averse to typing can use the package's nickname and write (:use :cl)
.
227
Using keywords instead of strings has another advantage—Allegro provides a "modern mode" Lisp in which the reader does no case conversion of names and in which, instead of a COMMON-LISP
package with uppercase names, provides a common-lisp
package with lowercase names. Strictly speaking, this Lisp isn't a conforming Common Lisp since all the names in the standard are defined to be uppercase. But if you write your DEFPACKAGE
forms using keyword symbols, they will work both in Common Lisp and in this near relative.
228
Some folks, instead of keywords, use uninterned symbols, using the #:
syntax.
(defpackage #:com.gigamonkeys.email-db
(:use #:common-lisp))
This saves a tiny bit of memory by not interning any symbols in the keyword package—the symbol can become garbage after DEFPACKAGE
(or the code it expands into) is done with it. However, the difference is so slight that it really boils down to a matter of aesthetics.
229
The reason to use IN-PACKAGE
instead of just SETF
ing *PACKAGE*
is that IN-PACKAGE
expands into code that will run when the file is compiled by COMPILE-FILE
as well as when the file is loaded, changing the way the reader reads the rest of the file during compilation.
230
In the REPL buffer in SLIME you can also change packages with a REPL shortcut. Type a comma, and then enter change-package
at the Command:
prompt.
231
During development, if you try to :use
a package that exports a symbol with the same name as a symbol already interned in the using package, Lisp will signal an error and typically offer you a restart that will unintern the offending symbol from the using package. For more on this, see the section "Package Gotchas."
232
The code for the "Practical" chapters, available from this book's Web site, uses the ASDF system definition library. ASDF stands for Another System Definition Facility.
233
Some Common Lisp implementations, such as Allegro and SBCL, provide a facility for "locking" the symbols in a particular package so they can be used in defining forms such as DEFUN
, DEFVAR
, and DEFCLASS
only when their home package is the current package.
234
The term loop keyword is a bit unfortunate, as loop keywords aren't keywords in the normal sense of being symbols in the KEYWORD
package. In fact, any symbol, from any package, with the appropriate name will do; the LOOP
macro cares only about their names. Typically, though, they're written with no package qualifier and are thus read (and interned as necessary) in the current package.
235
Because one of the goals of LOOP
is to allow loop expressions to be written with a quasi-English syntax, many of the keywords have synonyms that are treated the same by LOOP
but allow some freedom to express things in slightly more idiomatic English for different contexts.
236
You may wonder why LOOP
can't figure out whether it's looping over a list or a vector without needing different prepositions. This is another consequence of LOOP
being a macro: the value of the list or vector won't be known until runtime, but LOOP
, as a macro, has to generate code at compile time. And LOOP
's designers wanted it to generate extremely efficient code. To be able to generate efficient code for looping across, say, a vector, it needs to know at compile time that the value will be a vector at runtime—thus, the different prepositions are needed.
237
Don't ask me why LOOP
's authors chickened out on the no-parentheses style for the using
subclause.
238
The trick is to keep ahold of the tail of the list and add new cons cells by SETF
ing the CDR
of the tail. A handwritten equivalent of the code generated by (loop for i upto 10 collect i)
would look like this:
(do ((list nil) (tail nil) (i 0 (1+ i)))
((> i 10) list)
(let ((new (cons i nil)))
(if (null list)
(setf list new)
(setf (cdr tail) new))
(setf tail new)))
Of course you'll rarely, if ever, write code like that. You'll use either LOOP
or (if, for some reason, you don't want to use LOOP
) the standard PUSH
/ NREVERSE
idiom for collecting values.
239
Интервал:
Закладка:
Похожие книги на «Practical Common Lisp»
Представляем Вашему вниманию похожие книги на «Practical Common Lisp» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Practical Common Lisp» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.