Closed kazemihabib closed 11 months ago
This is a limitation of the Prolog Jupyter kernel unfortunately. When you write something like sunny.
in a cell, the kernel doesn't know if you want to define a new fact sunny
, or if you want to run a query that checks whether sunny
is true. In these ambiguous cases, the kernel assumes that it's meant as a query, because that's the more common case. As you already found out, you can work around this by adding :- true
or putting multiple facts in the same cell.
In a normal Prolog REPL, this ambiguity doesn't exist - there, all inputs are queries, unless you explicitly run consult(user).
to say that you are now inputting facts/clauses. Unfortunately, because of how Jupyter works, we cannot have multiple "input modes" like this in the Prolog Jupyter kernel, so we had to use this imperfect solution, where defining a single fact doesn't work as expected.
This is one of the issues that I solved differently in the Logtalk kernel (which was forked from this Prolog kernel): code cell contents is always interpreted as a query (or multiple queries) unless the code cell start with a cell magic telling that the contents that follow (directives and clauses) are to be added to the database.
I'm learning prolog and I noticed something weird with this kernel considering facts: If I put more than one facts in a cell it works properly:
outputs:
but if I try only one fact:
it outputs:
but the following works: