defStruct/2

Module: builtins

defStruct/2 — specify an abstract data type

FORMS

:- defStruct(TypeID, Equations) .

DESCRIPTION

Used as a directive to specify an abstract datatype. TypeID is an atom functioning identifying the type. Equations is a list of [equality statements] of the form :

      Left = Right

where the left component of the equality statements must be one of :

The right sides of equality statements are Prolog terms whose structure depends on the left side entry, as follows.

propertiesList
    A list of atoms or expressions which are the symbolic names, or names plus values, of the properties or slots of the structure being defined. Details a presented below.

For all of the rest of the equality statements, the right side is a single atom.

accessPred
    The name of the ternary(3-argument) predicate to be used for accessing the values of the slots in the structure. Calls on a generated accessPred take the form

<accessPred>(<slotname>, <Structure>, <Value>)

setPred
    The name of the ternary(3-argument) predicate to be used for setting or changing the values of the slots in the structure. Calls on a generated accessPred take the form

<setPred>(<slotname>, <Structure>, <Value>)

makePred
    The name of the unary predicate used for obtaining a fresh structure of the defined type.

structLabel
    The name of the functor of the structure defined.

In more detail, a propertiesList is a list of [slot specifications] as follows :

EXAMPLES

:- defStruct(windows,
     [ propertiesList =
        [ windowName, % name of the window
          windowNum,  % assigned by window sys
          borderColor/blue, % for color displays
          borderType/sing,  % single or double lines
          uLR, uLC,   % coords(Row, Col) of upper Left corner
          lRR, lRC,   % coords(Row, Col) of lower Right corner
          fore/black, % foreground/background
          back/white  % text attribs
        ],
        accessPred = accessWI,
        setPred = setWI,
        makePred = makeWindowStruct,
        structLabel = wi
     ] ).

Then :

     ..., makeWindowStruct(WIN),
     ..., setWI(windowName, WIN, foo),
     ..., accessWI(borderColor, WIN, BColor), ...