defStruct/2 — specify an abstract data type
:- defStruct(TypeID, Equations) .
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.
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.
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>)
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>)
The name of the unary predicate used for obtaining a fresh structure of the defined type.
The name of the functor of the structure defined.
In more detail, a
propertiesList is a list of [slot specifications] as follows :
an atom, which is the name of the particular slot, or
- an expression of the form
SlotNameis an atom serving as the name of this slot, and
Termis an arbitrary Prolog term which is the default value of this particular slot, or
expression which is a term of the form
Fileis a path to a file, and
Typeis the name of a
defStructwhich appears in that file; if
Filecan be located, and if the
File, the elements of propertiesList for
Typeare interpolated at the point where the include expression occurred; include expressions may be recursively nested. [Note : Relative paths in recursive includes must be valid from the directory in which the
defStructdirective was invoked. ]
:- 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 ] ).
..., makeWindowStruct(WIN), ..., setWI(windowName, WIN, foo), ..., accessWI(borderColor, WIN, BColor), ...