Sets are now implemented as a generic interface, and lists count as sets. Most
of the set functions have been added as methods, including mutable versions of
imperative update methods.
The definition form and function consume an equality predicate and optional hash
code functions and key predicate, and produce predicates and constructor
functions for hash table-based dictionaries using the given equality and hash
functions. Immutable, mutable, and weak dictionaries are defined.
- Added hash-empty?, hash-clear, and hash-clear! for hash tables.
- Added dict-empty?, dict-clear, and dict-clear! for dictionaries.
- Made all dict functions exported by racket/dict into generic methods; turned
the existing implementations into fallbacks.
The #:dispatch option specifies a second, less strict predicate for a #:defaults
or #:fast-defaults clause. The main predicate is still used for the generics
group's type predicate, but the dispatch predicate is used in choosing which
method implementation to use. The #:dispatch option is useful when the dispatch
predicate is disjoint from all other instances, is significantly cheaper to run
than the main predicate, and the full checks can be meaningfully deferred in
method implementations.
Specifically, this is useful in the implementation of iteration for
association-list dictionaries. The dict-iterate-{next,key,value} functions do
not need to test (andmap pair? dict) if the given dict is eq? to the one stored
in the given iterator. The dispatch predicate, list?, is much cheaper.
The #:defined-predicate option is like #:defined-table, but it defines a
two-argument predicate that only processes the requested method name and doesn't
allocate a hash table each time it is called.
Method implementations provided via #:fallbacks, #:defaults, and #:fast-defaults
are now called directly by method procedures rather than stored in a vector and
extracted by index. This should hopefully improve inlining for methods.
For datatypes that are disjoint with structs that might implement the generic,
this adds a "fast path" implementation that doesn't need to test for struct
properties.
This work is in preparation for widening the interface of gen:dict with
operations like dict-for-each, dict-update, etc., each with a fallback
implementation. The property prop:dict, with its documented, fixed-length
vector representation, cannot be extended, whereas a generic with optional
methods can be.
The define-generics form can now derive existing struct properties, so that any
instance of the new generics group is also an instance of the struct property.
Previously, a failure during the first-order checks would print out the name of
the full contract for all the methods, while describing the value for just one
method. This is both misleading, and incredibly verbose. The new version
prints out just the relevant contract.
when there is no containing paren
it used to return the beginning of the region (usually 0)
(this adjusts backward-containing-sexp to agree with the docs)