[plt-scheme] likely 3.99.0.22 -> 3.99.0.23 incompatibility: hash tables
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)
(fail)))
; 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)))
Matthew