For a general description, see Dynamic Tuples. Dynamic tuples are currently the only implementation of tuples.
To use tuples, you first need to declare some tuple keys. They can also be created dynamically, but this is less common.
A key in a tuple. All tuple keys must be of this type. These print as:
#<Key name>
Defines a tuple key named name as a global lexical variable. If
type is supplied, with operations using this key will check that the supplied value is
of that type; default is also checked. If default is supplied, it will be returned from
lookup, instead of nil, when the tuple has no pair with the given key. Alternatively,
if no-default? is true, lookup will signal an error in that case.
Creates a tuple key or updates an existing one. If name has not previously been used in the
current Lisp session to name a tuple key, creates a new one; otherwise, finds and updates the
existing one. In either case, returns the key. name should normally be a symbol, but can be
of any type known to FSet. type, default, and no-default? are treated as by
define-tuple-key, above.
The name given when the key was created.
The type of values associated with the key.
The abstract class for FSet functional tuples. Subclass of collection.
Returns true iff x is an FSet functional tuple.
Functional tuples implemented as dynamic tuples. Subclass of tuple. These print as:
#~< (k0 v0) (k1 v1) ... >
For each key, only its name is printed, without the #<Key …>.
Returns true iff x is an FSet functional dynamic tuple.
Constructor macro. Constructs a tuple of the default implementation, currently dyn-tuple,
according to the supplied argument subforms. Each argument subform can be a list of the form
(key-expr value-expr), denoting a mapping from the value of key-expr to the value
of value-expr; or a list of the form ($ expression), in which case the expression
must evaluate to a tuple, denoting all its mappings. The result is constructed from the denoted
mappings in left-to-right order; so if a given key is supplied by more than one argument subform,
its associated value will be given by the rightmost such subform.
Constructor macro. Constructs a dyn-tuple according to the supplied argument subforms. Each
argument subform can be a list of the form (key-expr value-expr), denoting a mapping
from the value of key-expr to the value of value-expr; or a list of the form ($
expression), in which case the expression must evaluate to a tuple, denoting all its
mappings. The result is constructed from the denoted mappings in left-to-right order; so if a given
key is supplied by more than one argument subform, its associated value will be given by the
rightmost such subform.
Returns the number of key/value pairs in tup. O(1).
The set of keys in tup. O(1).
Returns a new dynamic tuple that contains all pairs of tup whose key is not k, and also
maps k to v. If tup already maps k to a value equal? to v,
returns tup itself. If k was created with a type, checks that v is of that type,
signalling a tuple-value-type-error if not. O(n) in the worst case, but under reasonable assumptions, typically O(1) in practice.
If tup contains key k, returns the associated value. Otherwise, if k has a
default, returns that default. Otherwise, signals a tuple-key-unbound-error. O(n) in the
worst case, but under reasonable assumptions, typically O(1) in
practice..
Returns a new tuple containing all the keys of tuple1 and tuple2, where the value for each key contained in only one tuple is the value from that tuple, and the value for each key contained in both tuples is the result of calling val-fn on the value from tuple1 and the value from tuple2. val-fn defaults to simply returning its second argument, so the entries in tuple2 simply shadow those in tuple1. O(n).