| 1 | |
|---|
| 2 | :- protocol(dictionaryp). |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | :- info([ |
|---|
| 6 | version is 1.0, |
|---|
| 7 | authors is 'Paulo Moura', |
|---|
| 8 | date is 2000/7/24, |
|---|
| 9 | comment is 'Dictionary protocol.']). |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | :- public(as_dictionary/2). |
|---|
| 13 | |
|---|
| 14 | :- mode(as_dictionary(@list, -dictionary), one). |
|---|
| 15 | |
|---|
| 16 | :- info(as_dictionary/2, [ |
|---|
| 17 | comment is 'Converts a list of key-value pairs to a dictionary.', |
|---|
| 18 | argnames is ['List', 'Dictionary']]). |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | :- public(as_list/2). |
|---|
| 22 | |
|---|
| 23 | :- mode(as_list(@dictionary, -list), one). |
|---|
| 24 | |
|---|
| 25 | :- info(as_list/2, [ |
|---|
| 26 | comment is 'Converts a dictionary to a list of key-value pairs.', |
|---|
| 27 | argnames is ['Dictionary', 'List']]). |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | :- public(delete/4). |
|---|
| 31 | |
|---|
| 32 | :- mode(delete(+dictionary, @ground, ?term, -dictionary), zero_or_one). |
|---|
| 33 | |
|---|
| 34 | :- info(delete/4, [ |
|---|
| 35 | comment is 'Deletes a matching Key-Value pair from a dictionary, returning the updated dictionary.', |
|---|
| 36 | argnames is ['Dictionary_in', 'Key', 'Value', 'Dictionary_out']]). |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | :- public(empty/1). |
|---|
| 40 | |
|---|
| 41 | :- mode(empty(@dictionary), zero_or_one). |
|---|
| 42 | |
|---|
| 43 | :- info(empty/1, [ |
|---|
| 44 | comment is 'True if the dictionary is empty.', |
|---|
| 45 | argnames is ['Dictionary']]). |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | :- public(insert/4). |
|---|
| 49 | |
|---|
| 50 | :- mode(insert(+ground, @term, +dictionary, -dictionary), one). |
|---|
| 51 | |
|---|
| 52 | :- info(insert/4, [ |
|---|
| 53 | comment is 'Inserts a Key-Value pair into a dictionary, returning the updated dictionary.', |
|---|
| 54 | argnames is ['Key', 'Value', 'Dictionary_in', 'Dictionary_out']]). |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | :- public(insert_all/3). |
|---|
| 58 | |
|---|
| 59 | :- mode(insert_all(@list, +dictionary, -dictionary), one). |
|---|
| 60 | |
|---|
| 61 | :- info(insert_all/3, [ |
|---|
| 62 | comment is 'Inserts a list of Key-Value pairs into a dictionary, returning the updated dictionary.', |
|---|
| 63 | argnames is ['List', 'Dictionary_in', 'Dictionary_out']]). |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | :- public(lookup/3). |
|---|
| 67 | |
|---|
| 68 | :- mode(lookup(+ground, ?term, @dictionary), zero_or_one). |
|---|
| 69 | :- mode(lookup(-ground, ?term, @dictionary), zero_or_more). |
|---|
| 70 | |
|---|
| 71 | :- info(lookup/3, [ |
|---|
| 72 | comment is 'Get a matching Key-Value pair from a dictionary.', |
|---|
| 73 | argnames is ['Key', 'Value', 'Dictionary']]). |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | :- public(keys/2). |
|---|
| 77 | |
|---|
| 78 | :- mode(keys(@dictionary, -list), one). |
|---|
| 79 | |
|---|
| 80 | :- info(keys/2, [ |
|---|
| 81 | comment is 'Returns a list with all dictionary keys.', |
|---|
| 82 | argnames is ['Dictionary', 'List']]). |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | :- public(map/3). |
|---|
| 86 | |
|---|
| 87 | :- mode(map(+functor, +dictionary, -dictionary), zero_or_one). |
|---|
| 88 | |
|---|
| 89 | :- info(map/3, [ |
|---|
| 90 | comment is 'Maps a binary predicate over each dictionary key-value pair returning a new pair.', |
|---|
| 91 | argnames is ['Functor', 'In', 'Out']]). |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | :- public(size/2). |
|---|
| 95 | |
|---|
| 96 | :- mode(size(@dictionary, ?integer), zero_or_one). |
|---|
| 97 | |
|---|
| 98 | :- info(size/2, [ |
|---|
| 99 | comment is 'Number of dictionary entries.', |
|---|
| 100 | argnames is ['Dictionary', 'Size']]). |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | :- end_protocol. |
|---|