ATerm++

PrevUpHomeNext

Aterm properties

The aterms in the ATerm++ Library have some properties that need to be understood to use the library effectively. The aterm classes all wrap pointers to ATerm objects of the underlying ATerm Library. Copying an aterm is thus a very cheap operation.

Constant objects

A very important property of aterm objects is that they are constant. All member functions of the aterm classes (except the assignment operator) are constant.

All aterm objects are constant. Whenever you want to modify an attribute of an aterm, a new object has to be created.

Conversions

The class aterm is a base class for all other aterm types. To simplify the conversion between aterm and its derivatives, there are member functions to_int, to_appl etc. available, like in the following example:

aterm_int x(10);
aterm y = x;
aterm_int z = y.to_int();
assert(z.value() == 10);
aterm_appl f = make_term("f(x,y)").to_appl();

One might expect that by the assignment to y all information about being an aterm_int would be lost. This is not the case! After the assignment both x and y wrap the same ATerm pointer. And thus it is possible to convert y back to an aterm_int.

Maximal sharing

The ATerm Library uses maximal sharing of terms, which makes it very memory efficient. Any time a new aterm is created, a lookup is done to see if it already exists. If so, that term is reused and no new term is created. The following code fragment illustrates how this works:

aterm_appl f = make_term("f(g(a,b),c)").to_appl();
aterm_appl g = make_term("g(a,b)").to_appl();
assert(f.argument(0) == g);

aterm_list v = make_term("[1,2,3,4]").to_list();
aterm_list w = make_term("[0,1,2,3,4]").to_list();
assert(pop_front(w) == v);

If two lists have the same tail, these tails will be shared.

Global aterm objects

The garbage collector of the ATerm Library assumes that all aterms that are in use can be found on the stack. Any aterm that isn't on the stack (for example global variables) needs to be protected explicitly.

Aterm objects that are not on the stack must be protected from being garbage collected, using the protect member function.

Annotations

Aterm objects may be annotated by other aterms. In the following example y is an annotated version of x.

aterm x("f(a)");
aterm label("label");
aterm annotation("annotation");
aterm y = set_annotation(x, label, annotation);
assert(x != y);
Aterms with different annotations are considered to be different.
Copyright © 2004 Wieger Wesselink

PrevUpHomeNext