Implicitly bound variables

I’m using: SWI-Prolog version 9.2.7

I want the code to:

#!/usr/bin/python

import janus_swi as janus

query = janus.query("aggregate_all(count, between(0,3,X), C)")
print(query.next())

But what I’m getting is:
janus_swi.janus.PrologError: Arguments are not sufficiently instantiated

I have changed this to

#!/usr/bin/python

import janus_swi as janus

query = janus.query("aggregate_all(count, between(0,3,_), C)")
print(query.next())

than it is working.
But there are cases where I need more than one variable.
eg. Autumn Challenge 2024: Numbrix Puzzle - #6 by j4n_bur53

time(aggregate_all(count, (between(0,3,X),  between(0,3,Y), path((X,Y), [(X,Y)])), C)).

Thank you

All variables that do not start with an ‘_’ are made part of the result and thus must be convertible to Python after the query succeeds. So, the solution is to use variables like _MyVar for variables that need to be in the query (because they appear multiple times) but you do not want in the answer.

I’d typically keep my query short and use a rule (clause) to do the complicated things. Now only the arguments are visible.

Thank you very much this is working:

aggregate_all(count, (between(0,3,_X), between(0,3,_Y), path((_X,_Y), [(_X,_Y)])), C)