   (let [new-pair (kons item nil)]
     (if (empty-queue? queue)
       (do (set-front-ptr! queue new-pair)
-          (set-rear-ptr! queue new-pair)
-          queue)
+          (set-rear-ptr! queue new-pair))
       (do (set-cdr! (rear-ptr queue) new-pair)
-          (set-rear-ptr! queue new-pair)
-          queue))))
+          (set-rear-ptr! queue new-pair)))
+    queue))
 
 (defn delete-queue! [queue]
   (if (empty-queue? queue)

(defn lookup'' [keys table]
  (loop [keys keys
         table table]
    (let [subtable (assok (first keys) (cdr table))]
      (if subtable
        (if (empty? (rest keys))
          (cdr subtable)
          (recur (rest keys) subtable))
        false))))

;; FIXME
(defn insert!'' [keys value table]
  (loop [keys keys
         table table]
    (let [subtable (assok (first keys) (cdr table))]
      (if subtable
        (if (empty? (rest keys))
          (set-cdr! subtable value)
          (recur (rest keys) subtable))
        (set-cdr! table
                  (let [rkeys (reverse keys)]
                    (kons (reduce #(scheme-like-list %2 %1)
                                  (kons (first rkeys) value)
                                  (rest rkeys))
                          (cdr table)))))))
  :ok)

;;; 3.3.4  A Simulator for Digital Circuits

    dispatch))

;; Exercise 3.23
(defn make-deque []
  (kons nil nil))

(defn empty-deque? [deque]
  (nil? (front-ptr deque)))

(defn deque-element [item]
  (scheme-like-list item nil nil))
(defn deque-item [deque]
  (car deque))
(defn deque-next [deque]
  (car (cdr deque)))
(defn deque-previous [deque]
  (car (cdr (cdr deque))))
(defn set-deque-next! [deque ptr]
  (set-car! (cdr deque) ptr))
(defn set-deque-previous! [deque ptr]
  (set-car! (cdr (cdr deque)) ptr))

(defn deque->vector [deque]
  (loop [coll (front-ptr deque)
         v []]
    (if (nil? coll)
      v
      (recur (deque-next coll) (conj v (deque-item coll))))))

(defn front-deque [deque]
  (if (empty-deque? deque)
    (throw (IllegalArgumentException.
            (str "FRONT called with an empty deque "
                 (deque->vector deque))))
    (deque-item (front-ptr deque))))

(defn rear-deque [deque]
  (if (empty-deque? deque)
    (throw (IllegalArgumentException.
            (str "REAR called with an empty deque "
                 (deque->vector deque))))
    (deque-item (rear-ptr deque))))

(defn front-insert-deque! [deque item]
  (let [new-elem (deque-element item)]
    (if (empty-deque? deque)
      (do (set-front-ptr! deque new-elem)
          (set-rear-ptr! deque new-elem))
      (do (set-deque-next! new-elem (front-ptr deque))
          (set-deque-previous! (front-ptr deque) new-elem)
          (set-front-ptr! deque new-elem)))
    (deque->vector deque)))

(defn rear-insert-deque! [deque item]
  (let [new-elem (deque-element item)]
    (if (empty-deque? deque)
      (do (set-front-ptr! deque new-elem)
          (set-rear-ptr! deque new-elem))
      (do (set-deque-next! (rear-ptr deque) new-elem)
          (set-deque-previous! new-elem (rear-ptr deque))
          (set-rear-ptr! deque new-elem)))
    (deque->vector deque)))

(defn front-delete-deque! [deque]
  (if (empty-deque? deque)
    (throw (IllegalArgumentException.
            (str "DELETE called with an empty deque "
                 (deque->vector deque))))
    (do (if-let [next (deque-next (front-ptr deque))]
          (do (set-deque-previous! next nil)
              (set-front-ptr! deque next))
          (do (set-front-ptr! deque nil)
              (set-rear-ptr! deque nil)))
        (deque->vector deque))))

(defn rear-delete-deque! [deque]
  (if (empty-deque? deque)
    (throw (IllegalArgumentException.
            (str "DELETE called with an empty deque "
                 (deque->vector deque))))
    (do (if-let [previous (deque-previous (rear-ptr deque))]
          (do (set-deque-next! previous nil)
              (set-rear-ptr! deque previous))
          (do (set-front-ptr! deque nil)
              (set-rear-ptr! deque nil)))
        (deque->vector deque))))

;;; 3.3.3  Representing Tables

