root/tags/lgt2310/library/attributes.lgt

Revision 3769, 2.1 KB (checked in by pmoura, 19 months ago)

Fixed a spelling typo.

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