Course
Grades
Email
Welcome
Policies
Grades
Inc
Intgrty
Preface
Part I
Chap 1
Chap 2
Chap 3
XEmacs
Chap 4
Chap 5
Chap 6
Chap 7
Chap 8
Chap 9
Part II
Chap 10
Chap 11
Chap 12
Chap 13
Chap 14
Chap 15
Chap 16
Chap 17
Chap 18
Chap 19
Chap 20
Chap 21
Chap 22
Chap 23
Part III
Chap 24
Chap 25
Chap 26
Chap 27
Chap 28
Chap 29
Chap 30
Chap 31
Chap 32
|
CHAPTER 25: SCOPE AND EXTENT
- Corrections
- Page 184, line -1: Change (setq x 3) to
(setf x 3).
- Notes
-
- Read Chapter 25.
- Do Exercises 25.1 - 25.3 to the extent you feel you need to
in order to understand the material.
- Do Exercise 25.4. The text mentions that versions of Lisp
older than Common Lisp were dynamically scoped (instead of lexically
scoped, which Common Lisp is). The Lisp that was used to implement
XEmacs (and other versions of Emacs), called Emacs Lisp or ELisp, is
also dynamically scoped. You can see this by doing Exercise 25.4 in
the *scratch* buffer. The *scratch* buffer is a top-level listener
for Emacs Lisp, and is very similar to interacting with the top-level
of ACL, but to evaluate a form you type a C-j. That will evaluate the
immediately preceding form. Compare ACL's behavior to ELisp's
behavior on this exercise.
- Do Exercises 25.5 - 25.8 carefully to learn more about global and
local variables, and to learn about declarations.
- Create a file named
ch25.cl with one function
defined in the ch25 package. This should be a
function named stack that takes one optional argument
whose default value is the empty list. Let's say that lambda variable
is named stk . The function stack should
return a closure which is a function of one required argument called
operation and one optional argument called
element . The free variable of the closure should be the
variable stk . The closure should operate as follows:
- If
operation is the symbol push , use
setf to push the element onto
stk , and return the value of stk .
- If
operation is the symbol pop , use
setf to pop the top element off stk , and
return the value of stk .
- If
operation is the symbol top ,
return the top element of stk .
Here's an example of stack in operation:
CH25(19): (setf s1 (stack))
#<Interpreted Closure (:INTERNAL STACK) @ #x46b4742>
CH25(20): (funcall s1 'push 'z)
(Z)
CH25(21): (funcall s1 'push 'y)
(Y Z)
CH25(22): (setf s2 (stack '(m)))
#<Interpreted Closure (:INTERNAL STACK) @ #x46b4bba>
CH25(23): (funcall s2 'push 'a)
(A M)
CH25(24): (funcall s2 'push 'b)
(B A M)
CH25(25): (funcall s1 'pop)
(Z)
CH25(26): (funcall s1 'top)
Z
CH25(27): (funcall s2 'top)
B
Submit your ch25.cl
|