I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.
In the code below, you can see a function I created named my_apply/2
to apply a Goal to a list of arguments. This code works fine when I test it outside of PEngines in the SWI-Prolog console. However, when I pass the exact same code in the src_text
parameter during the creation of a PEngines instance, I get the following error back:
Sandbox restriction! Could not derive which predicate may be called from call(C) '329664db-065f-4c7d-9744-cc0db034997e':my_apply_1(u_assert(item_state(A,locked)),B) '329664db-065f-4c7d-9744-cc0db034997e':my_apply(u_assert(item_state(A,locked)),B) '329664db-065f-4c7d-9744-cc0db034997e':initialize_game
As you can also see in the code below during the initialize_game/0
predicate, the predicate named u_assert()
that I am using in the call to my_apply()
works fine when not being passed to my_apply()
. So I assume it must be something to do with trying to execute the predicate via the call()
method while in the PEngines sandbox, as the error indicates?
NOTE: The error occurs during the creation of the PEngines instance, not during a call to ask()
. It happens when the code I pass via src_text
executes some initialization code.
How can I get this working?
Here is the relevant code from the code I pass in the src_text
parameter during the creation of my PEngines instance:
% ----->>>>> u_assert/u_retract/u_retractall
% This predicate asserts an element of user data.
u_assert(UData) :-
nonvar(UData),
!,
assert(user_data(UData)).
% Handle assert or retract with goal with var() first argument.
apply_build_new_goal(OuterGoal, ListElement, Goal_2) :-
nonvar(OuterGoal),
nonvar(ListElement),
OuterGoal =.. [ OuterPredName, InnerGoal | OuterArgs],
member(OuterPredName,
[
assert,
retract,
u_assert,
u_retract
]),
nonvar(InnerGoal),
InnerGoal =.. [ InnerPredName, InnerFirstArg | InnerArgs ],
nonvar(InnerPredName),
var(InnerFirstArg),
!,
% Build the new inner goal with the list element given.
InnerGoal_2 =.. [ InnerPredName, ListElement | InnerArgs],
% Build the new outer goal.
Goal_2 =.. [ OuterPredName, InnerGoal_2 | OuterArgs].
% Handle plain goal with var() first argument..
apply_build_new_goal(Goal, ListElement, Goal_2) :-
nonvar(Goal),
nonvar(ListElement),
Goal =.. [ PredName, FirstArg | Args ],
nonvar(PredName),
var(FirstArg),
!,
Goal_2 =.. [ PredName, ListElement | Args].
% my_apply_1 iterates the list of elements to apply the given goal to.
my_apply_1(_, []) :- !.
my_apply_1(Goal, [H | T]) :-
!,
% Build the new goal using the current list element to act upon.
apply_build_new_goal(Goal, H, Goal_2),
% Apply the new goal.
call(Goal_2),
% Continue.
my_apply_1(Goal, T).
% Apply the given Goal to each element in the given list.
my_apply(Goal, TargetList) :-
nonvar(Goal),
nonvar(TargetList),
my_apply_1(Goal, TargetList).
This is the code that resides in the code passed via src_text
that “auto-runs” when the PEngine instance is created. The error happens during the call to my_apply()
:
initialize_game :-
pengine_output('INITIALIZING GAME!'),
u_assert(inventory(player_1, pork)),
% Lock ALL the rooms.
my_apply(u_assert(item_state(_, locked)), RoomList),