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

INTERN-LOCAL is the culprit



    Date: Mon, 4 Jul 88 18:30 EAST
    From: munnari!aaii.mu.oz.au!wilkins@uunet.UU.NET (David E. Wilkins)

    Since this works so poorly, what is the preferred way in 7.2 to generate names
    for thousands of created sturctures in such a way that the user can quickly and
    easily type these names back during later interaction?

If you know you'll have thousands, and you know you'll only use the
names as indexes (as opposed to binding them or funcalling them), you
can just manage the names yourself.

;;; First, make a table.
(setf *solution-obarray* (make-hash-table :test 'equal :size 5000))
;;; Compile it:
(sys:compile-table-flavor :test 'equal :size 5000)
;;; make a little structure
(defstruct (solution (:constructor make-solution-internal (name))
                     (:conc-name soln-)
                     :named
                     (:print-function print-solution))
    name data)
;;; This is how you map names to solutions:
(defun intern-solution (name &optional create-p)
  (or (gethash name *solution-obarray*)
      (and create-p (setf (gethash name *solution-obarray*)
			  (make-solution-internal name)))))

If you pick your numbers correctly you won't ever have to change the
form of the table.  Also, you won't have the storage overhead of the
parts of the symbols which you'll never use.  And you can stick all the
names for these guys in one area if you want that.

If you want to get fancy you can use a reader macro to make life easier
for your users, say: {solution-25}.

I prefer to keep away from symbols unless I want to do lispy things with
them (as I said, funcalling or binding them), because otherwise people
assume they can break abstraction and depend on lisp semantics applying
to them.

Toss a prawn on the barbie for me!