AI::Prolog::Builtins is a Perl module with builtin predicates that AI::Prolog supports.
Comments
Comments begin with a % and terminate at the end of the line or begin with /* and terminate with */.
Variables
As in Prolog, all variables begin with an upper-case letter and are not quoted. In the following example, STUFF is a variable.
steals(badguy, STUFF, "Some rich person").
Constants
Constants begin with lower-case letters. If you need a constant that begins with an upper-case letter or contains spaces or other non-alphanumeric characters, enclose the constant in single or double quotes The quotes will not be included in the constant.
In the following example, badguy and Some rich person are both constants:
steals(badguy, STUFF, "Some rich person").
Miscellaneous
This will not work:
p(X) :- X. /* does not work */
Use this instead:
p(X) :- call(X).
BUILTINS
!/0
The "cut" operator. This is used when you wish to tell Prolog that you only need to satisfy a goal once. For example, if you wish to deny someone the right to rent videos if they have overdue videos, you might use the cut operator as soon as you see they have any overdue video. The fact that they have more than one overdue video doesn't matter.
See the cut.pl program in the examples/ directory that comes with this distribution.
assert/1
Add new facts to the database. Only facts can be added, not rules. This may change in the future. See retract(X).
assert(loves(ovid,perl)).
call/1
Invokes X as a goal.
consult/1
Supplied the name of a file containing Prolog code, this will consult the Prolog code in the file and add its contents to the current knowledgebase.
Will warn if the file cannot be opened.
div/2
Succeeds if both terms are bound. The value of the term is X / Y. Use with is(X,Y).
is(X, div(N,3)).
This is the internal form of the infix operator:
N / 3.
eq/2
Succeeds if X and Y are equal.
This is the internal form of the infix operator:
X == Y.
fail/0
This goal always fails. Useful when you've reached a condition you know should not succeed.
kill(Hero, Beast) :-
not(has_weapon(Hero)), fail.
ge/2
Succeeds if both terms are bound and X >= Y.
This is the internal form of the infix operator:
X >= Y.
gt/2
Succeeds if both terms are bound and X > Y.
This is the internal form of the infix operator:
X > Y.
halt/1
In the aiprolog shell, exist shell. Currently has no other effect.
if/3
If X succeeds as a goal, try Y as a goal. Otherwise, try Z.
thief(badguy).
steals(PERP, X) :-
if(thief(PERP), eq(X,rubies), eq(X,nothing)).
is/2
If X is unbound and Y is bound to a number, the goal succeeds and X becomes bound to the value of Y. Otherwise, succeeds if both terms are bound, numbers, and equal.
All other conditions result in failure.
This is the internal form of the infix operator:
X is Y.
le/2
Succeeds if both terms are bound and X
Requirements:
· Perl