practical-language-learning

exercise-8

  1. Is it possible for two symbols to have the same name but not be eql?
  2. Estimate the difference between…
  3. The call to defpackage on page 137…
  4. Add the code necessary to make…
  5. Write a program that can…
  6. Write a version of Henley that…

Is it possible for two symbols to have the same name but not be eql?

YES, symbol is substantial object just like list, two symbol have same may point to defferent objects.

Estimate the difference between…

2.Estimate the difference between the amount of memory used to represent the string “FOO” and the amount used to represent the symbol foo.

The call to 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.

Add the code necessary to make…

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))

Write a program that can…

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)))

Write a version of Henley that…

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))))))