Recall two terms: An object is called “"alive"” as
long as it can be retrieved by the user or program, through any kind of
references, starting from global and local variables. (Objects that
consume no heap storage, also known as “"immediate
objects"”, such as CHARACTER
s, FIXNUM
s, and
SHORT-FLOAT
s, are alive indefinitely.) An object is said to be
garbage-collected when its storage is reclaimed, at some moment after it becomes
“"dead"”.
A EXT:WEAK-POINTER
is an object holding a reference to a given object,
without keeping the latter from being garbage-collected.
Weak Pointer API
(EXT:MAKE-WEAK-POINTER
value
)
EXT:WEAK-POINTER
referring to
value
.(EXT:WEAK-POINTER-P
object
)
object
is of type
EXT:WEAK-POINTER
.(EXT:WEAK-POINTER-VALUE
weak-pointer
)
T
,
if the value has not yet been garbage-collected, else NIL
and NIL
.
It is SETF
-able: you can change the value that the weak pointer
points to.Weak pointers are useful for notification-based communication
protocols between software modules, e.g. when a change to an object
x
requires a notification to an object y
, as long as y
is
alive.
A EXT:WEAK-LIST
is an ordered collection of references to objects
that does not keep the objects from being garbage-collected. It is
semantically equivalent to a list of EXT:WEAK-POINTER
s, however with a
more efficient in-memory representation than a plain list of
EXT:WEAK-POINTER
s would be.
Weak List API
(EXT:MAKE-WEAK-LIST
list
)
EXT:WEAK-LIST
pointing to each of the
elements in the given list
.(EXT:WEAK-LIST-P
object
)
object
is of type
EXT:WEAK-LIST
.(EXT:WEAK-LIST-LIST
weak-list
)
LIST
of those objects from the
weak-list
that are still
alive.(SETF
(EXT:WEAK-LIST-LIST
weak-list
) list
)
weak-list
.Weak lists are useful for notification based communication
protocols between software modules, e.g. when a change to an object
x
requires a notification to objects k1
, k2
, ..., as long
as such a particular kn
is alive.
A EXT:WEAK-LIST
with a single element is semantically equivalent to a
single EXT:WEAK-POINTER
.
A weak “and” relation is an ordered collection of references to objects, that does not keep the objects from being garbage-collected, and which allows access to all the objects as long as all of them are still alive. As soon as one of them is garbage-collected, the entire collection of objects becomes empty.
Weak “And” Relation API
(EXT:MAKE-WEAK-AND-RELATION
list
)
EXT:WEAK-AND-RELATION
between the objects in
the given list
.(EXT:WEAK-AND-RELATION-P
object
)
object
is of type
EXT:WEAK-AND-RELATION
.(EXT:WEAK-AND-RELATION-LIST
weak-and-relation
)
weak-and-relation
. The returned list must not
be destructively modified.EXT:WEAK-AND-RELATION
s are useful to model relations between objects
that become worthless when one of the objects dies.
A EXT:WEAK-AND-RELATION
with a single element is semantically
equivalent to a EXT:WEAK-POINTER
.
A weak “or” relation is an ordered collection of references to objects, that keeps all objects from being garbage-collected as long as one of them is still alive. In other words, each of them keeps all others among them from being garbage-collected. When all of them are unreferenced, the collection of objects becomes empty.
Weak “Or” Relation API
(EXT:MAKE-WEAK-OR-RELATION
list
)
EXT:WEAK-OR-RELATION
between the objects in
the given list
.(EXT:WEAK-OR-RELATION-P
object
)
object
is of type
EXT:WEAK-OR-RELATION
.(EXT:WEAK-OR-RELATION-LIST
weak-or-relation
)
weak-or-relation
. The returned list must not
be destructively modified.EXT:WEAK-OR-RELATION
s are useful to model relations between objects
that do not become worthless when one of the objects dies.
A EXT:WEAK-OR-RELATION
with a single element is semantically
equivalent to a EXT:WEAK-POINTER
.
A weak association is a mapping from an object called key
to
an object called value
, that exists as long as the key is alive. In
other words, as long as the key is alive, it keeps the value from being
garbage-collected.
Weak Association API
(EXT:MAKE-WEAK-MAPPING
key
value
)
EXT:WEAK-MAPPING
.
(EXT:WEAK-MAPPING-P
object
)
EXT:WEAK-MAPPING
.(EXT:WEAK-MAPPING-PAIR
weak-mapping
)
T
, if the key has not yet been garbage-collected, else NIL
, NIL
,
NIL
.(EXT:WEAK-MAPPING-VALUE
weak-mapping
)
NIL
.(SETF
(EXT:WEAK-MAPPING-VALUE
weak-mapping
) value
)
weak-mapping
. It has no effect when the
key has already been garbage-collected.Weak associations are useful to supplement objects with additional information that is stored outside of the object.
A weak “and” mapping is a mapping from a tuple of
objects called keys
to an object called value
, that does
not keep the keys from being garbage-collected and that exists as long as all
keys are alive. As soon as one of the keys is garbage-collected, the entire
mapping goes away.
Weak “And” Mapping API
(EXT:MAKE-WEAK-AND-MAPPING
keys
value
)
EXT:WEAK-AND-MAPPING
between the keys
objects in the given list and the given value
.
The keys
list must be non-empty.(EXT:WEAK-AND-MAPPING-P
object
)
object
is of type
EXT:WEAK-AND-MAPPING
.(EXT:WEAK-AND-MAPPING-PAIR
weak-and-mapping
)
T
, if none of the keys have been garbage-collected, else NIL
, NIL
, NIL
.
The returned keys list must not be destructively modified.
(EXT:WEAK-AND-MAPPING-VALUE
weak-and-mapping
)
NIL
.(SETF
(EXT:WEAK-AND-MAPPING-VALUE
weak-and-mapping
) value
)
weak-and-mapping
. It has no effect when
some key has already been garbage-collected.EXT:WEAK-AND-MAPPING
s are useful to model properties of sets of
objects that become worthless when one of the objects dies.
A EXT:WEAK-AND-MAPPING
with a single key is semantically equivalent
to a weak association.
A weak “or” mapping is a mapping from a tuple of
objects called keys
to an object called value
, that keeps all
keys and the value from being garbage-collected as long as one of the keys is
still alive. In other words, each of the keys keeps all others among
them and the value from being garbage-collected. When all of them are
unreferenced, the entire mapping goes away.
Weak “Or” Mapping API
(EXT:MAKE-WEAK-OR-MAPPING
keys
value
)
EXT:WEAK-OR-MAPPING
between the
keys
objects in the given list and the given
value
. The keys
list must be
non-empty.(EXT:WEAK-OR-MAPPING-P
object
)
object
is of type
EXT:WEAK-OR-MAPPING
.(EXT:WEAK-OR-MAPPING-PAIR
weak-or-mapping
)
T
, if the keys have not yet been garbage-collected, else NIL
, NIL
, NIL
.
The returned keys list must not be destructively modified.
(EXT:WEAK-OR-MAPPING-VALUE
weak-or-mapping
)
NIL
.(SETF
(EXT:WEAK-OR-MAPPING-VALUE
weak-or-mapping
) value
)
weak-or-mapping
. It has no effect when the
keys have already been garbage-collected.EXT:WEAK-OR-MAPPING
s are useful to model properties of sets of
objects that do not become worthless when one of the objects dies.
A EXT:WEAK-OR-MAPPING
with a single key is semantically equivalent
to a weak association.
A weak association list is an ordered collection of pairs, each
pair being built from an object called key
and an object called
value
. The lifetime of each pair depends on the type of the weak
association list:
:KEY
key
is not garbage-collected.
As long as the key
is alive, it prevents the value
from
being garbage-collected.:VALUE
value
is not garbage-collected.
As long as the value
is alive, it prevents the key
from
being garbage-collected.:KEY-AND-VALUE
key
and the value
are alive.
:KEY-OR-VALUE
key
or the value
are alive. As long as the key
is alive, it prevents the value
from being garbage-collected, and as long as the value
is alive, it prevents the
key
from being garbage-collected.In other words, each pair is:
:KEY
EXT:WEAK-MAPPING
from the key
to the value
,
:VALUE
EXT:WEAK-MAPPING
from the value
to the key
,
:KEY-AND-VALUE
EXT:WEAK-AND-RELATION
of the key
and the value
,
:KEY-OR-VALUE
EXT:WEAK-OR-RELATION
of the key
and the value
.
Weak Association List API
(EXT:MAKE-WEAK-ALIST
:type :initial-contents)
EXT:WEAK-ALIST
. The type
argument
must be one of the four aforementioned types; the default is :KEY
.
The initial-contents
argument must be an
association list.(EXT:WEAK-ALIST-P
object
)
object
is of type
EXT:WEAK-ALIST
.(EXT:WEAK-ALIST-TYPE
weak-alist
)
weak-alist
.(EXT:WEAK-ALIST-CONTENTS
weak-alist
)
weak-alist
.
(SETF
(EXT:WEAK-ALIST-CONTENTS
weak-alist
)
contents
)
weak-alist
. The
contents
argument must be an
association list.(EXT:WEAK-ALIST-ASSOC
item
weak-alist
[:test] [:test-not] [:key])
(ASSOC
item
(EXT:WEAK-ALIST-CONTENTS
weak-alist
)
[:test] [:test-not] [:key])
.
(EXT:WEAK-ALIST-RASSOC
item
weak-alist
[:test] [:test-not] [:key])
(RASSOC
item
(EXT:WEAK-ALIST-CONTENTS
weak-alist
)
[:test] [:test-not] [:key])
.
(EXT:WEAK-ALIST-VALUE
item
weak-alist
[:test] [:test-not])
(CDR
(EXT:WEAK-LIST-ASSOC
item
weak-alist
[:test] [:test-not]))
.
(SETF
(EXT:WEAK-ALIST-VALUE
item
weak-alist
[:test] [:test-not])
value
)
item
in
a weak-alist
. When a pair with the given
item
as key does not exist or has already been garbage-collected, a new pair
is added to the association list.Weak associations lists are useful to supplement objects with additional information that is stored outside of the object, when the number of such objects is known to be small.
A weak HASH-TABLE
is an unordered collection of pairs, each
pair being built from an object called key
and an object called
value
. There can be only one pair with a given key
in a weak
HASH-TABLE
. The lifetime of each pair depends on the type of the
weak HASH-TABLE
:KEY
key
is not garbage-collected.
As long as the key
is alive, it prevents the value
from
being garbage-collected.:VALUE
value
is not garbage-collected.
As long as the value
is alive, it prevents the key
from
being garbage-collected.:KEY-AND-VALUE
key
and the
value
are alive.:KEY-OR-VALUE
key
or the
value
are alive. As long as the key
is alive, it prevents
the key
from being garbage-collected, and as long as the value
is
alive, it prevents the key
from being garbage-collected.
In other words, each pair is:
:KEY
EXT:WEAK-MAPPING
from the key
to the value
,
:VALUE
EXT:WEAK-MAPPING
from the value
to the key
,
:KEY-AND-VALUE
EXT:WEAK-AND-RELATION
of the key
and the value
,
:KEY-OR-VALUE
EXT:WEAK-OR-RELATION
of the key
and the value
.
See also Section 18.2, “Function MAKE-HASH-TABLE
”.
Weak HASH-TABLE
s are useful to supplement objects with
additional information that is stored outside of the object. This data
structure scales up without performance degradation when the number of
pairs is big.
Weak HASH-TABLE
s are also useful to implement canonicalization
tables.
These notes document CLISP version 2.49 | Last modified: 2010-07-07 |