The [record][1]
library provides the ability to create compound terms with named fields. The directive :- record/1 <spec>
compiles to a collection of predicates that initialize, set and get fields in the term defined by <spec>
.
For example, we can define a point
data structure with named fields x
and y
:
:- use_module(library(record)).
:- record point(x:integer=0,
y:integer=0).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
?- default_point(Point), point_x(Point, X), set_x_of_point(10, Point, Point1).
Point = point(0, 0),
X = 0,
Point1 = point(10, 0).
?- make_point([y(20)], Point).
Point = point(0, 20).
?- is_point(X).
false.
?- is_point(point(_, _)).
false.
?- is_point(point(1, a)).
false.
?- is_point(point(1, 1)).
true.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */