This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/library/attributes.lgt
2001-06-06 19:40:57 +00:00

106 lines
2.2 KiB
Plaintext

:- category(attributes).
:- info([
version is 1.0,
authors is 'Paulo Moura',
date is 2000/7/24,
comment is 'Dynamic attributes dictionary.']).
:- public(attribute/2).
:- mode(attribute(?nonvar, ?nonvar), zero_or_more).
:- info(attribute/2,
[comment is 'Returns, by backtracking, all pairs of atribute-values.',
argnames is ['Attribute', 'Value']]).
:- public(attributes/1).
:- mode(attributes(-list), one).
:- info(attributes/1,
[comment is 'List of all pairs of atribute-values.',
argnames is ['Attributes']]).
:- private(attribute_/2).
:- dynamic(attribute_/2).
:- mode(attribute_(?nonvar, ?nonvar), zero_or_more).
:- info(attribute_/2,
[comment is 'Stores attributes values.',
argnames is ['Attribute', 'Value']]).
:- public(del_attribute/2).
:- mode(del_attribute(?nonvar, ?nonvar), zero_or_more).
:- info(del_attribute/2,
[comment is 'Deletes a matching attribute-value pair.',
argnames is ['Attribute', 'Value']]).
:- public(del_attributes/2).
:- mode(del_attributes(@term, @term), one).
:- info(del_attributes/2,
[comment is 'Deletes all matching attribute-value pairs.',
argnames is ['Attribute', 'Value']]).
:- public(set_attribute/2).
:- mode(set_attribute(+nonvar, +nonvar), one).
:- info(set_attribute/2,
[comment is 'Sets an attribute value.',
argnames is ['Attribute', 'Value']]).
:- public(set_attributes/1).
:- mode(set_attributes(+list), one).
:- info(set_attributes/1,
[comment is 'Sets a list of attribute-value pairs.',
argnames is ['Attributes']]).
attribute(Attribute, Value) :-
::attribute_(Attribute, Value).
attributes(Attributes) :-
findall(Attribute, ::attribute_(Attribute, _), Attributes).
del_attribute(Attribute, Value) :-
::retract(attribute_(Attribute, Value)).
del_attributes(Attribute, Value) :-
::retractall(attribute_(Attribute, Value)).
set_attribute(Attribute, Value) :-
::retractall(attribute_(Attribute, _)),
::assertz(attribute_(Attribute, Value)).
set_attributes([]).
set_attributes([Attribute-Value| Attributes]) :-
::retractall(attribute_(Attribute, _)),
::assertz(attribute_(Attribute, Value)),
set_attributes(Attributes).
:- end_category.