Can't use term_to_json/2 because of Pengines sandbox?

I am using SWI-Prolog 8.0.2 on Ubuntu Linux 18.0.4.

I have my Node.JS code that calls into Pengines running now, but instead of getting a JSON object response I am getting what appears to be some kind of “internal” or “native” format that uses functor and args properties to describe the Prolog result that is generated by a query to my Pengines code:

[{"Report":[{"args":[{"args":[{"args":["move_player_to"],"functor":"trigger_action"},{"args":["attic"],"functor":"target"},{"args":["move_to_adjacent_room"],"functor":"prerequisites_list"}],"functor":"details"}],"functor":"prerequisite"}]}]

This is what that looks like when the code is run outside of Pengines, directly in the SWI-Prolog console:

Report = [prerequisite(details(trigger_action(move_player_to), target(attic), prerequisites_list(move_to_adjacent_room)))].

I read the PEngines documentation and it mentions a predicate called term_to_json/2:

http://www.swi-prolog.org/pldoc/doc_for?object=section('packages/pengines.html')

But when I try to use that function from my code I get the following error:

No permission to call sandboxed `numbervars(_1040,_1042,_1044,_1046)’
Reachable from:

findall(_1068,(maplist(bind_var,_1084),numbervars(_1094,0,_1098,singletons(true)]),to_json(_1094,_1068)),[_1120])
term_to_json:term_to_json(A,B,C)\n\t tsll:term_to_json(A,B)

This puzzles me because I thought term_to_json/2 was made specifically for Pengines usage? Either way, what is the simplest way for my Node.JS code that calls into Pengines to get a typical JSON object in response from a query instead of the functor/args format I am currently getting?

term_to_json/2 is called as part of the reply generation outside the sandbox. Nevertheless, there is no reason for numbervars/4 not to be considered safe. Added.

To reply a nice json term, make sure the predicate binds the result to a dict, e.g.

Report = json{target:attic, ...}
1 Like

Thanks! I’m on SWI-Prolog 8.0.2. I’ll upgrade on the next stable release to get that change.