[plt-scheme] likely -> incompatibility: hash tables

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 7 20:51:20 EDT 2008

At Mon, 07 Apr 2008 19:25:38 -0400, Prabhakar Ragde wrote:
> Matthew Flatt wrote:
> > While we're cleaning up the language in v4, we'd like to do something
> > about the API for using hash tables:
> I appreciate and support the idea of simplifying the syntax, but the use 
> of both "table" and "hash-table" confuses me. I suppose it is related to 
> this:
> > * Add some property for creating new kinds of tables. The property
> >    value supplies an implementation for `table-ref', etc.
> Can you sketch an example of how this would work?

Not a great example, but here's a vector wrapped as a table:

 (define-struct vector-table (vec)
   #:property prop:table (list
                          ; table-ref
                          (lambda (nt key fail)
                            (if (and (exact-nonnegative-integer? key)
                                     (key . < . (vector-length
                                                 (vector-table-vec nt))))
                                (vector-ref (vector-table-vec nt) key)
                          ; table-set!
                          (lambda (nt key val)
                            ; need better error message for bad key...
                            (vector-set! (vector-table-vec nt) key val))
                          ; table-count
                          (lambda (nt)
                            (vector-length (vector-table-vec nt)))

  (define (create-vector-table size)
    (make-vector-table (make-vector size #f)))


Posted on the users mailing list.