Reputation: 7738
I have just started learning Prolog
and so pardon me if this is a bit naive, or rather a lot naive. I am trying to define this predicate
| ?- times(M,N,Product) :- Product is M*N.
which gives me this error
uncaught exception: error(existence_error(procedure,(:-)/2),top_level/0)
I am using GNU Prolog. What is the fault here ?
Upvotes: 3
Views: 2565
Reputation: 648
Check user manual 8.7 Dynamic clause management especially: asserta/assertz.
Next will help you to define new predicate in gprolog:
asserta( ( times(M,N,Product) :- Product is M*N ) ).
Upvotes: 0
Reputation: 14778
As false said, If you want to define a predicate or function during the execution of the interpreter, you must enter the "user" mode of the interpreter, by typing:
['user'].
After typing your predicates, you'll just need to leave this "zone", as a confirmation to the interpreter that you're finished with the coding, and it can start to compile your predicates to bytecodes -- which you'll be, then, allowed to access through your function names.
To leave the "user" mode simply press ctrl + d
.
Tested in both swipl and gprolog:
SWI-Prolog version 5.10.4
(GNU Prolog) 1.3.0
Regards!
Upvotes: 6