You are looking at historical revision 16420 of this page. It may differ significantly from its current revision.
Purports to be a simple key -> value lookup table. Known as a 'Dictionary' in some circles. It attempts to optimize for speed of lookup by choosing different storage models.
- Bugs and Limitations
- Version history
make-dict[procedure] (make-dict [EQUALITY eq? [ESTIMATE <small-number>]])
Returns a dictionary using the supplied EQUALITY test, optimized for the number of elements ESTIMATE.
alist->dict[procedure] (alist->dict ALIST [EQUALITY eq?] [ESTIMATE 0])
Returns a dictionary constructed from ALIST using the supplied EQUALITY test, and optional ESTIMATE.
dict?[procedure] (dict? OBJECT)
Is the OBJECT a dictionary?
dict-equivalence-function[procedure] (dict-equivalence-function DICT)
Returns the equality test predicate procedure for DICT.
dict-count[procedure] (dict-count DICT)
Returns the number of items in the DICT.
dict-keys[procedure] (dict-keys DICT)
Returns the keys in the DICT.
dict-values[procedure] (dict-values DICT)
Returns the values in the DICT.
dict->alist[procedure] (dict->alist DICT)
Returns the DICT as an association list. The result may not be mutated!
dict-ref[procedure] (dict-ref DICT KEY [DEFAULT #f])
Returns the value associated with KEY in the DICT, otherwise DEFAULT.
dict-Idempotent-ref![procedure] (dict-Idempotent-ref! DICT KEY FUNC [DEFAULT #f])
Should a value for KEY exist in DICT it is returned. Otherwise FUNC is invoked on DEFAULT. Any result other than DEFAULT is the value for the KEY and that value is returned. Otherwise returns DEFAULT.
dict-exists?[procedure] (dict-exists? DICT KEY)
Does an entry with KEY exist in the DICT ?
dict-set![procedure] (dict-set! DICT KEY VALUE)
Associate VALUE with KEY in the DICT.
VALUE must not be (void)!
dict-update![procedure] (dict-update! DICT KEY DEFAULT-VALUE-PROCEDURE [FUNC identity])
Invokes FUNC on either the existing value for KEY in the DICT, or the result of the DEFAULT-VALUE-PROCEDURE when no existing value. The result then becomes the value for KEY in the DICT.
Returns the updated value for KEY in the DICT.
DEFAULT-VALUE-PROCEDURE must not return (void)!
dict-update-list![procedure] (dict-update-list! DICT KEY [OBJECT]...)
Updates the value for KEY in the DICT with a list of OBJECT.
dict-update-dict![procedure] (dict-update-dict! DICT KEY [EQUALITY eq? [ESTIMATE <small-number>]])
Updates the value for KEY in the DICT with a dictionay.
EQUALITY and ESTIMATE as for make-dict.
dict-delete![procedure] (dict-delete! DICT KEY)
Removes any association of KEY in the DICT.
dict-for-each[procedure] (dict-for-each DICT (PROCEDURE (-> KEY VALUE <ignored>)))
Invokes the supplied PROCEDURE with each association in the DICT.
dict-merge![procedure] (dict-merge! DICT [DICT1...])
Returns the DICT as the union of ( DICT DICT1 ...) using overwrite semantics.
Tables must have the same equality predicate.
dict-search[procedure] (dict-search DICT (PROCEDURE (-> object object boolean)) [DEFAULT #f])
Accepts a PROCEDURE of two arguments, key and value. When the procedure returns (code #t) this procedure returns the value. Otherwise the DEFAULT value is returned.)
dict-print[procedure] (dict-print DICT [PORT (current-output-port)])
Pretty-print DICT to PORT.
or for no argument checking and return of actual representation:
Bugs and Limitations
- Added 'make-dict' parameters to 'dict-update-dict!'.
- Added 'dict-Idempotent-ref!' and 'synch' versions.
- Split into safe & unsafe
- Fix for strange compile output (C procedures being redefined).
- Use of primitives.
- Chicken 4 release.
Copyright (C) 2009 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.