record.pl -- Access compound arguments by name
This module creates a set of predicates to create a default instance, access and modify records represented as a compound term.
The full documentation is with record/1, which must be used as a directive. Here is a simple example declaration and some calls.
:- record point(x:integer=0, y:integer=0). default_point(Point), point_x(Point, X), set_x_of_point(10, Point, Point1), make_point([y(20)], YPoint),
- record(+RecordDef)
- Define access predicates for a compound-term. RecordDef is of
the form <constructor>(<argument>, ...), where each argument
is of the form:
- <name>[:<type>][=<default>]
Used a directive,
:- record Constructor(Arg, ...)
is expanded info the following predicates:<constructor>_<name>
(Record, Value)<constructor>_data
(?Name, ?Record, ?Value)default_<constructor>
(-Record)is_<constructor>
(@Term)make_<constructor>
(+Fields, -Record)make_<constructor>
(+Fields, -Record, -RestFields)set_<name>_of_<constructor>
(+Value, +OldRecord, -New)set_<name>_of_<constructor>
(+Value, !Record)nb_set_<name>_of_<constructor>
(+Value, !Record)set_<constructor>_fields
(+Fields, +Record0, -Record).set_<constructor>_fields
(+Fields, +Record0, -Record, -RestFields).set_<constructor>_field
(+Field, +Record0, -Record).user:current_record
(:<constructor>)
- compile_records(+RecordsDefs, -Clauses) is det[private]
- Compile a record specification into a list of clauses.
- compile_record(+Record)// is det[private]
- Create clauses for Record.
- current_record(?Name, :Term)
- True if Name is the name of a record defined in the module associated with Term and Term is the user-provided record declaration.
- current_record_predicate(?Record, ?PI) is nondet
- True if PI is the predicate indicator for an access predicate to Record. This predicate is intended to support cross-referencer tools.
- make_predicate(+Constructor)// is det[private]
- Creates the make_<constructor>(+Fields, -Record) predicate. This
looks like this:
make_<constructor>(Fields, Record) :- make_<constructor>(Fields, Record, []) make_<constructor>(Fields, Record, RestFields) :- default_<constructor>(Record0), set_<constructor>_fields(Fields, Record0, Record, RestFields). set_<constructor>_fields(Fields, Record0, Record) :- set_<constructor>_fields(Fields, Record0, Record, []). set_<constructor>_fields([], Record, Record, []). set_<constructor>_fields([H|T], Record0, Record, RestFields) :- ( set_<constructor>_field(H, Record0, Record1) -> set_<constructor>_fields(T, Record1, Record, RestFields) ; RestFields = [H|RF], set_<constructor>_fields(T, Record0, Record, RF) ). set_<constructor>_field(<name1>(Value), Record0, Record). ...
- is_predicate(+Constructor, +Types)// is det[private]
- Create a clause that tests for a given record type.
- type_goal(+Type, +Var, -BodyTerm) is det[private]
- Inline type checking calls.
- access_predicates(+Names, +Idx0, +Arity, +Constructor)// is det[private]
- Create the <constructor>_<name>(Record, Value) predicates.
- data_predicate(+Names, +Idx0, +Arity, +Constructor, +DataName)// is det[private]
- Create the <constructor>_
data(Name, Record, Value)
predicate. - set_predicates(+Names, +Idx0, +Arity, +Types, +Constructor)// is det[private]
- Create the clauses
- set_<name>_of_<constructor>(Value, Old, New)
- set_<name>_of_<constructor>(Value, Record)
- set_field_predicates(+Names, +Idx0, +Arity, +Types, +Constructor)// is det[private]
- Create the clauses
- set_<constructor>_field(<name>(Value), Old, New)
- replace_nth(+Index, +List, +Element, -NewList) is det[private]
- Replace the Nth (1-based) element of a list.
- defaults(+ArgsSpecs, -Defaults, -Args)[private]
- Strip the default specification from the argument specification.
- types(+ArgsSpecs, -Defaults, -Args)[private]
- Strip the default specification from the argument specification.