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