Collections, sequences and mappings

dfsch provides abstraction for common collection types. Collections of objects (accessible only for iteration), ordered sequences and mappings (called dictionaries or hashes in other languages). These data types are accessed by common set of functions regardless of their real underlying implementation.


Collection is abstraction for object that can be iterated over. All objects implementing <<collection>> can be passed to function collection-iterator which returns iterator that in some sense iterates over contents of given collection.

Interface of iterators is designed to be partialy compatible with ordinary Lisp lists - that is, lists can be directly used as iterators. However, steping iterator to next element may modify iterator itself. Function iter-this returns object that iterator points to (and is thus equivalent to car), on the other hand iter-next! returns iterator pointing to next element or empty list, when no more elements are avaiable. Reusing argument to iter-next! in any way produces unpredictable results (except when iter-next! returns it's argument).

Function coerce-collection returns collection of given type with same contents as collection that it's its first argument. Functions collection->list and collection->reversed-list convert collections to lists, with second one being slightly faster.


Objects implementing indexed collections of other object are so called sequence objects and implement <<sequence>>. These objects can be accessed by functions seq-ref and seq-set!. It's apparent, that most sequences are also collections.


Mappings support accessor map-ref and setters map-set! and map-unset!. In addition to this, mappings also provide conditionalized setters map-set-if-exists! and map-set-if-not-exists!. Most mappings can be iterated over like <<collection>>, elements returned by iterator are intended to be lists of key and value although some mapping types return only keys. Keys and values separately can be iterated over by iterators returned from map-keys and map-values.

Functions operating on collections

Generated by docgen.scm running on dfsch 0.4.0 (bp-0.4.0-18-g88df03b) on 2012-04-16 10:00:28