Skip to content

Commit

Permalink
register_remote_code
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Jan 13, 2024
1 parent 1415f15 commit 8e27825
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions metta_vspace/pyswip/metta_server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@
% Example usage
% ?- remote_call('localhost', member(X, [1,2,3])).

:- dynamic predicate_server/2. % Maps predicate to server
:- dynamic remote_code/3. % Maps predicate to server

% Registers a predicate to a server
register_predicate_server(Predicate, Server) :- assertz(predicate_server(Predicate, Server)).
register_remote_code(Predicate, NonDet, Server) :- assertz(remote_code(Predicate, NonDet, Server)).

% Meta-interpreter with cut handling
execute_goal(Goal, IsCut) :-
predicate_server(Goal, Server), !, % If the goal is registered for a server, call remotely
remote_code(Goal, NonDet, Server), % If the goal is registered for a server, call remotely
(was_t(NonDet) -> true ; !),
remote_call(Server, execute_goal(Goal,IsCut)).


execute_goal(!, IsCut) :- !, IsCut = true. % Handle cuts
execute_goal(fail, IsCut) :- !, (was_t(IsCut)->throw(cut_fail); fail).
execute_goal(Goal, _) :- predicate_property(Goal,numberr_of_clauses(_)),!,
execute_goal(Goal, _) :- predicate_property(Goal,number_of_clauses(_)),!,
clause(Goal, Body), % Retrieve the clause body for the goal
catch(execute_goal(Body, IsCut),cut_fail,(!,fail)),
(was_t(IsCut)-> !; true).
Expand Down

0 comments on commit 8e27825

Please sign in to comment.