77

Though the standard doesn't specify how to incorporate multithreading into Common Lisp, implementations that provide multithreading follow the practice established on the Lisp machines and create dynamic bindings on a per-thread basis. A reference to a global variable will find the binding most recently established in the current thread, or the global binding.

78

This is why dynamic variables are also sometimes called special variables.

79

If you must know, you can look up DECLARE, SPECIAL, and LOCALLY in the HyperSpec.

80

Several key constants defined by the language itself don't follow this convention—not least of which are T and NIL. This is occasionally annoying when one wants to use t as a local variable name. Another is PI, which holds the best long-float approximation of the mathematical constant pi.

81

Some old-school Lispers prefer to use SETQ with variables, but modern style tends to use SETF for all assignments.

82

Look up DEFSETF, DEFINE-SETF- EXPANDER for more information.

83

The prevalence of Algol-derived syntax for assignment with the 'place' on the left side of the = and the new value on the right side has spawned the terminology lvalue, short for 'left value,' meaning something that can be assigned to, and rvalue, meaning something that provides a value. A compiler hacker would say, 'SETF treats its first argument as an lvalue.'

84

C programmers may want to think of variables and other places as holding a pointer to the real object; assigning to a variable simply changes what object it points to while assigning to a part of a composite object is similar to indirecting through the pointer to the actual object. C++ programmers should note that the behavior of = in C++ when dealing with objects—namely, a memberwise copy—is quite idiosyncratic.

85

To see what this misunderstanding looks like, find any longish Usenet thread cross-posted between comp.lang.lisp and any other comp.lang.* group with macro in the subject. A rough paraphrase goes like this:

Lispnik: 'Lisp is the best because of its macros!';

Othernik: 'You think Lisp is good because of macros?! But macros are horrible and evil; Lisp must be horrible and evil.'

86

Another important class of language constructs that are defined using macros are all the definitional constructs such as DEFUN, DEFPARAMETER, DEFVAR, and others. In Chapter 24 you'll define your own definitional macros that will allow you to concisely write code for reading and writing binary data.

87

You can't actually feed this definition to Lisp because it's illegal to redefine names in the COMMON- LISP package where WHEN comes from. If you really want to try writing such a macro, you'd need to change the name to something else, such as my-when.

88

Вы читаете Practical Common Lisp
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату