I think this is a scope related problem. If I have a rule on my object like this:
:- public(new/2).
:- mode(new(+list, -object_identifier), one).
new(Args, Instance) :-
self(Self),
create_object(Instance, [instantiates(Self)], [], []),
Instance::process_arguments(Args).
I find this works fine if I do this dance:
:- object(name, instantiates(name)).
I don't fully understand why this is necessary but I suspect it is linked to my actual problem, which is that if I have your standard Prolog loop in my object, like so:
process_arguments([Arg|Args]) :- process_arg(Arg), process_arguments(Args).
process_arguments([]).
process_arg(Arg) :- ::asserta(something(Arg)).
I find this use of ::asserta
puts the facts in the right namespace (on the newly-created instance). However, if I get witty and replace the body of process_arguments/1
with this lambda expression:
process_arguments(Args) :- meta::map([Arg]>>process_arg(Arg), Args).
then I wind up with my facts being added to the parent class and shared by all the instances. If I replace it with this:
process_arguments(Args) :-
self(Self),
meta::map([Arg]>>(Self::process_arg(Arg)), Args).
then it works, but I have to make process_arg/1
a public rule when I'd rather not. What am I missing?