I verified that this doesn’t work on the latest build, but the latest build has had some fixes so that it doesn’t hang anymore, but it does return an exception (which is what a recent fix fixed).
I’m curious though, did this exact code used to work using swiplserver?
Edit: The problem boils down to the fact that this code throws (everything after dict_create
is the code that MQI runs to serialize the result:
?- dict_create(D,proof, [1-a,2-b]),
term_to_json:term_to_json(D, Json),
with_output_to(string(Json_String),
(current_output(Stream), json:json_write(Stream, Json))).
ERROR: Type error: `text' expected, found `1' (an integer)
ERROR: In:
ERROR: [11] with_output_to(string(_176784),(current_output(_176794),json: ...))
ERROR: [10] '<meta-call>'(user:user: ...) <foreign>
ERROR: [9] toplevel_call(user:user: ...) at /Applications/SWI-Prolog.app/Contents/swipl/boot/toplevel.pl:1162
I’ll dig in tomorrow and see if I can figure out the fix.
Edit: SWI Prolog dicts support keys that are integers, JSON does not. json_write/2 (and json_write_dict/2) throw if you try to serialize a dict with an integer key to JSON and that’s what’s going on here.
Edit: I’m trying to see how pengines solves this issue (so I can copy that approach) or if it exists there too, but I’m not sure how to get a pengine set up to be serializing raw JSON as a response. I did figure out that using the pengines reply_json/1 predicate hits the same issue, so I suspect the same issue exists there:
http_json:reply_json(proof{1:a,2:b}).
Content-type: application/json; charset=UTF-8
{
ERROR: Type error: `text' expected, found `1' (an integer)
ERROR: In:
...