I am new to Prolog and I have so far learned how to define a predicate in a file and the run the interpreter to use it. But I would like to know if there is a way to define the predicate at the ?- prompt so that I don't have to switch back and forth.
the way I am doing it now is like this
file defs.pl:
adjacent(1,2).
adjacent(1,3).
in the prolog interpreter:
?- consult('defs.pl').
% defs.pl compiled 0.00 sec, 122 bytes
true.
?- adjacent(1,2).
true.
EDIT maybe I meant how to define 'facts' I'm not sure.
Prolog predicate is the method to contain the argument and return the boolean values such as true or false. It is a function to operate and return given values, variables, or arguments using a prolog programming language.
Goals relating to user-defined predicates are evaluated by examining the database of rules and facts loaded by the user. Prolog attempts to satisfy a goal by matching it with the heads of clauses in the database, working from top to bottom.
Prolog in Artificial Intelligence The not predicate is used to negate some statement, which means, when a statement is true, then not(statement) will be false, otherwise if the statement is false, then not(statement) will be true. If X and Y match, then different(X,Y) fails, Otherwise different(X,Y) succeeds.
You can use the assert/1
predicate:
?- assert(adjacent(1,4)).
true
EDIT: By the way, this will not work if you try to combine it with predicates defined in a file. So either define all adjacent/2 predicates in your file, are define them all with assert in the command line.
If you do want to define some of the predicates in the file, and others with assert, then declare in your file that the predicate is dynamic:
% file contents
:- dynamic(adjacent/2).
adjacent(1,2).
adjacent(1,3).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With