\chapter{Tutorial}

This chapter is a brief introduction to using the PROLOGIO package.

First, some terminology.  A {\it Prolog database}\/ is a list of {\it clauses},
each of which represents an object or record which needs to be saved to a file.
A clause has a {\it functor}\/ (name), and a list of attributes, each of which
has a value.  Attributes may take the following types of value: string, word,
integer, floating point number, and list.  A list can itself contain any
type, allowing for nested data structures.

Consider the following code.

\begin{verbatim}
PrologDatabase db;

PrologExpr *my_clause = new PrologExpr("object");
my_clause->AddAttributeValue("id", (long)1);
my_clause->AddAttributeValueString("name", "Julian Smart");
db.Append(my_clause);

ofstream file("my_file");
db.WriteProlog(file);
\end{verbatim}

This creates a database, constructs a clause, adds it to the database,
and writes the whole database to a file.  The file it produces looks like
this:

\begin{verbatim}
object(id = 1,
  name = "Julian Smart").
\end{verbatim}

To read the database back in, the following will work:

\begin{verbatim}
PrologDatabase db;
db.ReadProlog("my_file");

db.BeginFind();

PrologExpr *my_clause = db.FindClauseByFunctor("object");
int id = 0;
char *name = copystring("None found");

my_clause->AssignAttributeValue("id", &id);
my_clause->AssignAttributeValue("name", &name);

cout << "Id is " << id << ", name is " << name << "\n";
\end{verbatim}

Note the setting of defaults before attempting to retrieve attribute values,
since they may not be found.
