book, I always use #'.
67
Dynamic variables are also sometimes called
68
Early Lisps tended to use dynamic variables for local variables, at least when interpreted. Elisp, the Lisp dialect used in Emacs, is a bit of a throwback in this respect, continuing to support only dynamic variables. Other languages have recapitulated this transition from dynamic to lexical variables—Perl's local
variables, for instance, are dynamic while its my
variables, introduced in Perl 5, are lexical. Python never had true dynamic variables but only introduced true lexical scoping in version 2.2. (Python's lexical variables are still somewhat limited compared to Lisp's because of the conflation of assignment and binding in the language's syntax.)
69
Actually, it's not quite true to say that all type errors will always be detected—it's possible to use optional declarations to tell the compiler that certain variables will always contain objects of a particular type and to turn off runtime type checking in certain regions of code. However, declarations of this sort are used to optimize code after it has been developed and debugged, not during normal development.
70
As an optimization certain kinds of objects, such as integers below a certain size and characters, may be represented directly in memory where other objects would be represented by a pointer to the actual object. However, since integers and characters are immutable, it doesn't matter that there may be multiple copies of 'the same' object in different variables. This is the root of the difference between EQ
and EQL
discussed in Chapter 4.
71
In compiler-writer terms Common Lisp functions are 'pass-by-value.' However, the values that are passed are references to objects. This is similar to how Java and Python work.
72
The variables in LET
forms and function parameters are created by exactly the same mechanism. In fact, in some Lisp dialects—though not Common Lisp— LET
is simply a macro that expands into a call to an anonymous function. That is, in those dialects, the following:
(let ((x 10)) (format t '~a' x))
is a macro form that expands into this:
((lambda (x) (format t '~a' x)) 10)
73
Java disguises global variables as public static fields, C uses extern
variables, and Python's module-level and Perl's package-level variables can likewise be accessed from anywhere.
74
If you specifically want to reset a DEFVAR
ed variable, you can either set it directly with SETF
or make it unbound using MAKUNBOUND
and then reevaluate the DEFVAR
form.
75
The strategy of temporarily reassigning *standard-output* also breaks if the system is multithreaded—if there are multiple threads of control trying to print to different streams at the same time, they'll all try to set the global variable to the stream they want to use, stomping all over each other. You could use a lock to control access to the global variable, but then you're not really getting the benefit of multiple concurrent threads, since whatever thread is printing has to lock out all the other threads until it's done even if they want to print to a different stream.
76
The technical term for the interval during which references may be made to a binding is its