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

visible hash tables

It bothers me that hash tables cannot be made "visible" data structures, i.e.,
there is no pretty printer switch you can set to see what's inside them.
Compare this with:

 Vectors:  contents displayed in #() notation if *PRINT-ARRAY* is T.

 Arrays:  contents displayed in #nA() notation if *PRINT-ARRAY* is T.

 Structures:  normally displayed in #S notation.  As previously discussed,
  there should be a simple way to select #<> notation for structures, e.g., 
  if a flag named *PRINT-STRUCTURE* is NIL.

In teaching beginning to intermediate level Lispers to use hash tables, I find
my job would be a lot easier if they could see inside the things, just as they
can see inside structures and vectors.  So what about a convention for printing
hash tables?  Here is a suggestion:

  (setq a (make-hash-table))    ;make a hash table
  (setf (gethash 'foo a) 37)    ;put some stuff in it
  (setf (gethash 'bar a) 42)    ;put some more stuff in it

  (setf *print-hash* t)		;turn on the magic printer flag

  a ==>  #65H(EQL (FOO . 37) (BAR . 42))

The basic notation is:

  #nH(type (key1 . value1) (key2 . value2) ...)

where "n" is the size of the hash table and "type" is the type, such as
EQL.  The ordering of the dotted pairs is arbitrary.  Comments?

-- Dave