Download Lpp User`s Manual
Transcript
Chapter 1: Introduction 6 1.3 Using Lpp Using the Lpp library is easy. First you need to include in your C++ file #include <Lpp.hh> In some fussy cases you may want to include LppPure.hh here instead of Lpp.h, but Lpp.hh is always safe to use, See Section 1.5 [Pure Lisp Include File], page 10. Second, you need to link the library libLpp.a with the compile of your C++ program. libLpp.a gets installed on your system when Lpp is installed, See Section 1.2 [Installing Lpp], page 4. For example on Linux if you had installed Lpp under /usr/local and then wrote a C++ program that used Lpp called main.cc then the following would first compile a program main.cc and then make an executable called pgm c++ -I/usr/local/include -c main.cc c++ -o pgm main.o /usr/local/lib/lpp/libLpp.a Then after that, if you are familiar with Common Lisp, you will find that writing programs using Lpp is similar to writing programs in Common Lisp. A big advantage is that you can mix quite freely the static style of C++ with the dynamic style of Lisp without having to think about it too much. In the next section we give a simple example to illustrate this. 1.4 A Simple Data Base Example In this example we create a class that implements a simple data base. We then create an instance of the data base and populate it with some entities, namely some people. And finally we generate a report on the people of a family that we used to populate the data base to show the relational aspect of the data base. Lpp is useful here since we want entities to be any kind of object and hence dynamically bound objects will index the data base. In the example we use Lpp symbols to designate entities. We set relations in the data base with a typical entity attribute value tuple. So the data base access member functions are as follows • getSize() = Returns the total number of entities in the data base • addEntity(entity) = Add entity (any Lpp object) to the data base • setValue(entity, attribute, value) = Add a relation for entity • getValue(entity, attribute) = Returns the attribute value for entity Here is the implementation of the data base class