Closed vladiulianbogdan closed 3 years ago
Hello,
Thank you for raising this issue.
The cause of this problem is how the select/3
built-in predicate is implemented in Projog. The Projog version does not work when the second argument is a variable.
Expected behaviour:
?- select(a, Result, [x,y,z]).
Result = [a,x,y,z]
yes
Result = [x,a,y,z]
yes
Result = [x,y,a,z]
yes
Result = [x,y,z,a]
yes
Actual behaviour:
?- select(a, Result, [x,y,z]).
Expected list but got: VARIABLE
I have attached a zip file - issue117.zip - containing a Maven project that demonstrates a workaround for this. The project contains a class named com.example.SelectBugFix
which provides a new implementation for select/3
that fixes this bug. The src/main/resources/selectbugfix-projog-bootstrap.pl
file configures Projog to use SelectBugFix
for select/3
, instead of the version provided by Projog. The com.example.Issue117Example
class references selectbugfix-projog-bootstrap.pl
when creating the Projog
object.
Running com.example.Issue117Example
produces the output:
true
.(.(11, .(20, .(31, .(42, [])))), .(.(41, .(52, [])), .(.(6, .(5, .(3, .(4, .(1, .(2, .(12, .(23, [])))))))), [])))
[[11,20,31,42],[41,52],[6,5,3,4,1,2,12,23]]
I suggest you add SelectBugFix
and selectbugfix-projog-bootstrap.pl
to your project and configure it in the same way as is done in Issue117Example
. If you'd like to move SelectBugFix
to a different package (instead of com.example
) then you will also need to update the package name referenced in selectbugfix-projog-bootstrap.pl
.
I hope this workaround is satisfactory for you. I will include this bugfix in a future version of Projog, at which point you will no longer need this workaround.
Thanks again for raising this issue. If there is anymore I can do to help then please let me know.
Thank you for raising this issue. I have included a fix for this in the latest version of Projog - 0.4.0
.
There have been a few changes in this latest version of Java (e.g. package structure has been reorganised, moved from Java 7 to Java 8, minor changes to the API). The following projects provide examples of how the latest version of Projog can be used to call Prolog from Java.
https://github.com/s-webber/prolog-wumpus-world https://github.com/s-webber/prolog-expert-system https://github.com/s-webber/projog-examples/tree/master/calling-prolog-from-java
I have attached the following ZIP file demonstrating how the Prolog code you included in the description of this issue can be called from Java:
If you have anymore questions about Projog then please raise a new issue and I will take a look.
Thanks.
Hello,
I have tried to use Projog today and I have encountered the following problem.
I am using the following prolog code.
If I run the following query "all_possibilities([1, 2, 3, 4, 5, 6], [[11, 20, 31, 42], [41, 52], [12, 23]], [[1, 2], [3, 4]], Result)." in SWI-Prolog I do get an answer.
However when I run the following code in Java I get the exception.
The exception is:
One important thing to mention is that I am using version 0.3.0 because I was not able to import 0.4.0 using maven.
Thank you very much for this project, it is really useful!