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
Most Prolog query processors have an optimization,
in that they suppress non-instantiated variables,
when showing answer substitutions:
/* Example 1 */
?- X = X, Y = 2.
Y = 2.
/* Example 2 */
?- \+ \+ X = 1, Y = 2.
Y = 2.
Etc...
But this would be also a legal answer substitutions:
/* Example 1 */
?- X = X, Y = 2.
X = _1234,
Y = 2.
/* Example 2 */
?- \+ \+ X = 1, Y = 2.
X = _1234,
Y = 2.
Etc...
So maybe you can provoke the error as well with
something else ? I am saying the error might also
appear in certain queries without aggregate_all/3.
jan
October 3, 2024, 11:53am
3
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)