[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

hash-table puzzlement

Could someone be so kinda as to tell me why this program reports
different values after compilation?

(eval-when (load compile eval)
  (defvar base)
  (defvar copies)
  (defstruct base
    (table (make-hash-table :test #'equal) :type hash-table))

  (defstruct copies
    (table1 (make-hash-table :test #'equal) :type hash-table)
    (table2 (make-hash-table :test #'equal) :type hash-table))

  (defun make-and-store-values-in-table ()
    (setq base (make-base))
    (setf (gethash "STR1" (base-table base)) 1)
    (setf (gethash "STR2" (base-table base)) 2)
    (setf (gethash "STR3" (base-table base)) 3)

  (defun make-and-store-values-in-two-tables ()
    (setq copies (make-copies))
    (maphash #'(lambda (key value) 
		 (setf (gethash key (copies-table1 copies)) value)
		 (setf (gethash key (copies-table2 copies)) value))
	     (base-table base))

(defconstant base-stored `#.(make-and-store-values-in-table))
(defconstant copies-stored `#.(make-and-store-values-in-two-tables))

(princ (gethash "STR1" (copies-table1 copies-stored))) (terpri)
(princ (gethash "STR1" (copies-table2 copies-stored))) (terpri)