![]() |
The ATerm++ Library contains two types that can be used for creating hierarchies of terms: aterm_list (a singly linked list) and aterm_appl (a function application). Both can contain nested lists and function applications. For example:
aterm_list v("[1,[2,3],4]"); aterm_appl f("f(a,(g(b,c))"));
The class aterm_list has been modeled as a constant singly linked list. It has a C++ standard conforming iterator interface. Thus it operates well with the C++ Standard Library, as illustrated by the following example:
#include <algorithm> #include <iostream> #include "atermpp/aterm.h" using namespace std; using namespace genspect; struct counter { int& m_sum; counter(int& sum) : m_sum(sum) {} void operator()(const aterm& t) { m_sum += t.to_int().value(); } }; int main() { aterm_list q = make_term("[1,2,3,4]").to_list(); int sum = 0; for_each(q.begin(), q.end(), counter(sum)); assert(sum == 10); for (aterm_list::iterator i = q.begin(); i != q.end(); ++i) { cout << *i; } }
An aterm_appl is a function application. It consists of a function symbol (of type function_symbol) and a list of arguments (of type aterm_list).
![]() |
function_symbol s("\"F\"", 1, false); // s == "F", not quoted aterm_appl f(s, aterm("x")); // convert to string and back aterm_appl g = make_term(f.to_string()).to_appl(); assert(g.is_quoted()); // g.function() == F, quoted(!)
Copyright © 2004 Wieger Wesselink |