使用库(记录)使用命名字段的术语
[record][1] 库提供了使用命名字段创建复合术语的功能。指令:- record/1 <spec> 编译为一组谓词,用于初始化,设置和获取 <spec> 定义的术语中的字段。
例如,我们可以使用命名字段 x 和 y 定义 point 数据结构:
:- 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.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */