eql
?defpackage
on page 137…eql
?YES, symbol is substantial object just like list, two symbol have same may point to defferent objects.
2.Estimate the difference between the amount of memory used to represent the string “FOO” and the amount used to represent the symbol foo
.
foo
is symbol, is a object, maybe refer to function, variable, property list, or name.defpackage
on page 137…3.The call to defpackage
on page 137 used only strings as arguments. We could have used symbols instead. Why might this have been dangerous?
symbol is accessed in current package, not global accessible.
4.Add the code necessary to make the code in Figure 7.1 be in a package named “RING”, and that in Figure 7.2 be in a package named “FILE”. The existing code should remain unchanged.(7.4 Example: String Substitution)
(defpackage :com.string-substitution.ring
(:use :common-lisp)
(:export
:new-buf :buf-insert :buf-pop :buf-next :buf-reset :buf-clear :buf-flush))
(defpackage :com.string-substitution.file
(:use :common-lisp :com.string-substitution.ring)
(:export :file-subst))
5.Write a program that can verify whether or not a quote was produced by Henley (section 8.8).
(defun henley-text-p (text)
(and (hash-table-p text)
(random-next text)))
6.Write a version of Henley that can take a word and generate a sentence with that word in the middle of it(section 8.8).
(defun generate-middle-text (prev)
(let* ((choices (gethash prev *words*))
(i (/ (reduce #'+ choices :key #'cdr) 2)))
(dolist (pair choices)
(if (minusp (decf i (cdr pair)))
(return (car pair))))))