Programming in XPCE/Prolog: Section 6.1

## 6.1 XPCE is not Prolog!

Data managed by Prolog consists of logical variables, atoms, integers, floats and compound terms (including lists). XPCE has natural counterparts for atoms (a name object), integers (a XPCE int) and floating point numbers (a real object). Prolog logical variables and compound terms however have no direct counterpart in the XPCE environment. XPCE has variables (class var), but these obey totally different scoping and binding rules.

Where Prolog uses a compound term to represent data that belongs together (e.g. person(Name, Age, Address)), XPCE uses objects for this purpose:7This example uses XPCE user-defined classes. The details of this mechanism do not matter for the argument in this section. User-defined classes are described in chapter 7.

    :- pce_begin_class(person(name, age, address), object).

    variable(name,    name,   both, "Name of the person").
    variable(age,     int,    both, "Age in years").
    variable(address, string, both, "Full address").

    initialise(P, Name:name, Age:int, Address:string) :->
            "Create from name, age and address"::
            send(P, name, Name),
            send(P, age, Age),
            send(P, address, Address).

    :- pce_end_class.

    1 ?- new(P, person(fred, 30, 'Long Street 45')).
    P = @3664437/person

These two representations have very different properties:

- Equality
  Prolog cannot distinguish between ``person('Fred', 30, 'Long Street 45')`' and a second instance of the same term. In XPCE two instances of the same class having the same state are different entities.
- Attributes
  Whereas an attribute (argument) of a Prolog term is either a logical variable or instantiated to a Prolog data object, an attribute of an object may be assigned to. The assignment is destructive.
- Types
  XPCE is a dynamically typed language and XPCE object attributes may have types. Prolog is untyped.