1 | :- module(pltables_export_tools, [ | |
2 | merge_attributes/3 | |
3 | ]). | |
4 | ||
5 | :- use_module(probsrc(self_check)). | |
6 | :- use_module(probsrc(module_information)). | |
7 | ||
8 | :- module_info(group,pltables). | |
9 | :- module_info(description,'Tools used by several of the export modules'). | |
10 | ||
11 | % ---- | |
12 | % internal: merging of attribute lists | |
13 | % first list: low priority, merge in | |
14 | % second list: high priority, keep | |
15 | % third list: Result | |
16 | % ---- | |
17 | :-assert_must_succeed(pltables_export_tools:merge_attributes([],[],[])). | |
18 | :-assert_must_succeed(pltables_export_tools:merge_attributes([],[attr(x)],[attr(x)])). | |
19 | :-assert_must_succeed(pltables_export_tools:merge_attributes([attr(x)],[attr2(y)],[attr(x),attr2(y)])). | |
20 | :-assert_must_succeed(pltables_export_tools:merge_attributes([attr(y)],[attr(x)],[attr(x)])). | |
21 | merge_attributes([], Res, Res). | |
22 | merge_attributes([Attr | Attrs], HiPri, Res) :- | |
23 | functor(Attr, AttrName, Arity), | |
24 | functor(EmptyAttr, AttrName, Arity), | |
25 | merge_attributes(Attrs, HiPri, Res1), | |
26 | (member(EmptyAttr, HiPri) -> Res = Res1 ; Res = [Attr | Res1]). |