root/tags/lgt2311/library/dictionaryp.lgt

Revision 3687, 2.4 KB (checked in by pmoura, 21 months ago)

Code reformating.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- protocol(dictionaryp).
3
4    :- info([
5        version is 1.0,
6        author is 'Paulo Moura',
7        date is 2000/7/24,
8        comment is 'Dictionary protocol.']).
9
10    :- public(as_dictionary/2).
11    :- mode(as_dictionary(@list, -dictionary), one).
12    :- info(as_dictionary/2, [
13        comment is 'Converts a list of key-value pairs to a dictionary.',
14        argnames is ['List', 'Dictionary']]).
15
16    :- public(as_list/2).
17    :- mode(as_list(@dictionary, -list), one).
18    :- info(as_list/2, [
19        comment is 'Converts a dictionary to a list of key-value pairs.',
20        argnames is ['Dictionary', 'List']]).
21
22    :- public(delete/4).
23    :- mode(delete(+dictionary, @ground, ?term, -dictionary), zero_or_one).
24    :- info(delete/4, [
25        comment is 'Deletes a matching Key-Value pair from a dictionary, returning the updated dictionary.',
26        argnames is ['Dictionary_in', 'Key', 'Value', 'Dictionary_out']]).
27
28    :- public(empty/1).
29    :- mode(empty(@dictionary), zero_or_one).
30    :- info(empty/1, [
31        comment is 'True if the dictionary is empty.',
32        argnames is ['Dictionary']]).
33
34    :- public(insert/4).
35    :- mode(insert(+ground, @term, +dictionary, -dictionary), one).
36    :- info(insert/4, [
37        comment is 'Inserts a Key-Value pair into a dictionary, returning the updated dictionary.',
38        argnames is ['Key', 'Value', 'Dictionary_in', 'Dictionary_out']]).
39
40    :- public(insert_all/3).
41    :- mode(insert_all(@list, +dictionary, -dictionary), one).
42    :- info(insert_all/3, [
43        comment is 'Inserts a list of Key-Value pairs into a dictionary, returning the updated dictionary.',
44        argnames is ['List', 'Dictionary_in', 'Dictionary_out']]).
45
46    :- public(lookup/3).
47    :- mode(lookup(+ground, ?term, @dictionary), zero_or_one).
48    :- mode(lookup(-ground, ?term, @dictionary), zero_or_more).
49    :- info(lookup/3, [
50        comment is 'Get a matching Key-Value pair from a dictionary.',
51        argnames is ['Key', 'Value', 'Dictionary']]).
52
53    :- public(keys/2).
54    :- mode(keys(@dictionary, -list), one).
55    :- info(keys/2, [
56        comment is 'Returns a list with all dictionary keys.',
57        argnames is ['Dictionary', 'List']]).
58
59    :- public(map/3).
60    :- mode(map(+functor, +dictionary, -dictionary), zero_or_one).
61    :- info(map/3, [
62        comment is 'Maps a binary predicate over each dictionary key-value pair returning a new pair.',
63        argnames is ['Functor', 'In', 'Out']]).
64
65    :- public(size/2).
66    :- mode(size(@dictionary, ?integer), zero_or_one).
67    :- info(size/2, [
68        comment is 'Number of dictionary entries.',
69        argnames is ['Dictionary', 'Size']]).
70
71:- end_protocol.
Note: See TracBrowser for help on using the browser.