root/tags/lgt290/library/attributes.lgt

Revision 2, 2.2 KB (checked in by pmoura, 7 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- category(attributes).
3
4
5    :- info([
6        version is 1.0,
7        authors is 'Paulo Moura',
8        date is 2000/7/24,
9        comment is 'Dynamic attributes dictionary.']).
10
11
12    :- public(attribute/2).
13
14    :- mode(attribute(?nonvar, ?nonvar), zero_or_more).
15
16    :- info(attribute/2,
17        [comment is 'Returns, by backtracking, all pairs of atribute-values.',
18         argnames is ['Attribute', 'Value']]).
19
20
21    :- public(attributes/1).
22
23    :- mode(attributes(-list), one).
24
25    :- info(attributes/1,
26        [comment is 'List of all pairs of atribute-values.',
27         argnames is ['Attributes']]).
28
29
30    :- private(attribute_/2).
31    :- dynamic(attribute_/2).
32
33    :- mode(attribute_(?nonvar, ?nonvar), zero_or_more).
34
35    :- info(attribute_/2,
36        [comment is 'Stores attributes values.',
37         argnames is ['Attribute', 'Value']]).
38
39
40    :- public(del_attribute/2).
41
42    :- mode(del_attribute(?nonvar, ?nonvar), zero_or_more).
43
44    :- info(del_attribute/2,
45        [comment is 'Deletes a matching attribute-value pair.',
46         argnames is ['Attribute', 'Value']]).
47
48
49    :- public(del_attributes/2).
50
51    :- mode(del_attributes(@term, @term), one).
52
53    :- info(del_attributes/2,
54        [comment is 'Deletes all matching attribute-value pairs.',
55         argnames is ['Attribute', 'Value']]).
56
57
58    :- public(set_attribute/2).
59
60    :- mode(set_attribute(+nonvar, +nonvar), one).
61
62    :- info(set_attribute/2,
63        [comment is 'Sets an attribute value.',
64         argnames is ['Attribute', 'Value']]).
65
66
67    :- public(set_attributes/1).
68
69    :- mode(set_attributes(+list), one).
70
71    :- info(set_attributes/1,
72        [comment is 'Sets a list of attribute-value pairs.',
73         argnames is ['Attributes']]).
74
75
76    attribute(Attribute, Value) :-
77        ::attribute_(Attribute, Value).
78
79
80    attributes(Attributes) :-
81        findall(Attribute, ::attribute_(Attribute, _), Attributes).
82
83
84    del_attribute(Attribute, Value) :-
85        ::retract(attribute_(Attribute, Value)).
86
87
88    del_attributes(Attribute, Value) :-
89        ::retractall(attribute_(Attribute, Value)).
90
91
92    set_attribute(Attribute, Value) :-
93        ::retractall(attribute_(Attribute, _)),
94        ::assertz(attribute_(Attribute, Value)).
95
96
97    set_attributes([]).
98
99    set_attributes([Attribute-Value| Attributes]) :-
100        ::retractall(attribute_(Attribute, _)),
101        ::assertz(attribute_(Attribute, Value)),
102        set_attributes(Attributes).
103
104
105:- end_category.
Note: See TracBrowser for help on using the browser.