Unable to create Fact in Jekejeke Prolog

632 Views Asked by At

I'm using the Seven Languages In Seven Weeks Prolog tutorial and trying to run through some examples using the Android Jekejeke Runtime. For example, if I add

likes(wallace, grommit).

from the tutorial, I get.

Error: Undefined, private or package local predicate likes/2

I tried using assert, as described in How to create a fact in SWI-Prolog?, but then it says that assert is undefined, instead of likes.

Presumably I'm missing something basic about how the runtime works, or its dialect of prolog.it.

2

There are 2 best solutions below

2
Paulo Moura On BEST ANSWER

assert/1 is not a standard predicate, although several implementations provide it. That doesn't seem to be the case for Jekejeke Prolog. Use instead either the asserta/1 or the assertz/1 standard predicates. The first asserts a clause as the first for the predicate. The latter asserts a clause as the last for the predicate.

1
AudioBubble On

This is a common error. Namely that there is a certain assumption that facts can be entered in the top level directly by typing it.

The interpreter issues an error since he understands what is input as a query and the predicate in the query is yet undefined.

But the end-user has multiple options:

1) First option use assertz/1 or asserta/1:
The top level is for executing goals. You need a goal that instructs interpreter to perform an assert. Use asserta/1 or assertz/1:

Top-level:

?- assertz(likes(foo, bar)).

Please not that predicates that have already been used as a static predicate, i.e. have been added by method 2) or 3), cannot be anymore asserted. Use the dynamic/1 directive then.

The built-in assert/1 is not supported since it is not part of the ISO core standard and usually redundant to assertz/1.

2) Second option use a file and consult it:
Place the facts and rules into a file. And consult it via the consult/1 built-in.

File baz.p:

likes(foo, bar).

Top-level:

?- consult('baz.p').

Instead of consult/1 you can also use ensure_loaded/1 or use_module/1.

3) Third option directly consult from console:
Enter the facts and rules directly in the top-level. Finish your entering of facts and rules by the end-of-file key stroke.

Top-level:

?- [user].
likes(foo, bar).
^D

Bye