jsabater(a)iiia.csic.es says:
The probem is the following. Although message/1 is declared as concurrent, when the predicate main/0 arrives to the second retract_fact(message(B)) instead of waiting, it fails (as if message/1 was declared as data or dynamic). What's wrong in my code?
There's nothing wrong, in fact. Concurrent attributes are not working yet in Ciao (neither in 1.6 #3). We will try to put it working for 1.8 (coming soon).
If what you want is not a concurrent attribute (different for each instance) but a concurrent fact (common for all instances), i.e., a concurrent *class* attribute, then you can define it in a separate module and import it into the class. This workaround is the way to define class attributes in OCiao, whether concurrent or not.
This will do:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- class(test,[],[]).
:- use_module(testattributes,[message/1]).
:- export([main/0]).
main :- asserta_fact(message(a)), retract_fact(message(A)), display(A),nl, retract_fact(message(B)), display(B),nl.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(testattributes,[message/1],[]).
:- concurrent message/1.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Now, you can simulate a concurrent instance attribute by indexing the concurrent class attribute. Something like this:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- class(test,[],[]).
:- use_module(testattributes,[message/2]).
:- export([main/0]).
main :- self(S), asserta_fact(message(S,a)), retract_fact(message(S,A)), display(A),nl, retract_fact(message(S,B)), display(B),nl.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
:- module(testattributes,[message/2],[]).
:- concurrent message/2.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ok. This makes the predicate concurrent for every instance of the class. What you can do to avoid this is to create concurrent predicates dynamically for each instance, using the library(concurrency):concurrent/1 predicate. This will require some more programming... ;-)
Regards,
Paco ------- End of forwarded message -------