PROLOG TOOLS

<<Back to "examples" page

INDEX:


SYMBOLS

SYMBOL

DESCRIPTION

EXAMPLES

( ) Enclose objects and follows the relationship.
  • likes(john,mary).
 .  Ends a fact, called the stop character.
  • likes(john,mary).
  • human(socrates).

 "Group of Facts"
A group of facts are called Data Bases.
  • male(albert).
  • male(alice).
  • female(alice).
  • female(victoria).
  • parents(edward,victoria,albert).
  • parents(alice,victoria,albert).
"Capital Letters" Words that start off with capital letters are variables.
  • ?- likes(mary,X).
, Separates two statements or objects.  when between two statements than it is conjunction   and means "and".
  • ?- likes(mary,X), likes(john,X).
 :- The symbol for "if". Called a rule.
  • sister_of(X,Y) :-
    female(X),
    parents(X,M,F),
    parents(Y,M,F).
= Equality and Matching
  • ?- rides(clerk,bicycle) = X.
  • policeman = policeman *[succeeds]
  • bike(trek) = bike(X) *[X is instantiated to trek]
' echo string
  • ?- write('Hello World').
% comment precursor
  • % My first program.
; used after a query result that succceeds - means backtrack (unbinding of variable)
  • ?- likes(john, X).
    X = mary ;
    X = wine ;
is means '=', but everything after the '=' must be known or defined
  • f is c * 9.

SYNTAX

 

call ______________ exit ----->| |-----> | GOAL | | | <-----| |<----- fail ______________ redo


SAMPLE CODE/SYNTAX

CODE

DESCRIPTION

CALL/OUTPUT

mortal_report:-
write('Known mortals are: '),nl,
mortal(X),
tab(3),
write(X), nl,
fail.
Report writing code. write is built in predicate meaning put on the screen. nl is built in predicate meaning new line. tab is built in predicate meaning tab over n number of spaces.
?- mortal_report.
Known mortals are: 
   socrates
   plato
   zeno
   aristotle
no
?-
?- room(office). goal(querypattern).
yes
room(X) :-
location(X).
rule
?- room(living_room).
yes
?- location(Thing, Place). goal(querypattern x 2).
Thing = apple
Place = kitchen
pred(arg1, arg2, ... argN). Syntax for a fact.

IN CODE:

customer('John Malcovich', boston, good_credit).

predicate_name/3 Syntax for a describing a record. means predicate_name with three arguments customer('John Malcovich', boston, good_credit).
write('Known mortals are: ') Syntax for a the Built in Predicate write/1 Known mortals are:
write('Known mortals are: '),nl,
mortal(X)
Syntax for a the Built in Predicate nl/0 Known mortals are:
socrates
plato
zeno
aristotle
tab(3) Syntax for a the Built in Predicate tab/1(integer) yes
write(X), nl,
fail.
Syntax for a the Built in Predicate fail/0 socrates
plato
zeno
aristotle
no
?-
?- room(office). goal or query pattern yes
?- location(Thing, Place). two goals or query patterns Thing = apple
Place = kitchen
?- location(X, kitchen), edible(X). compound query X = apple
<<Back to "examples" page