Escolar Documentos
Profissional Documentos
Cultura Documentos
http://www.cs.oswego.edu/~odendahl/manuals/prolog/intro/index.html
Termino Definicion
statement one of fact, rule, or query
deductive formulation
whereby new facts can be
rule (cf. predicate)
inferred from existing
facts
a statement asking about
query
the existence of a fact(s)
logic program collection of rules
collection of facts that can
meaning of a logic
be deduced from any set
program
of initial facts
Loading files
predicate examples
consult('predicates.p').
consult(+Files) consult(['data1','data2']).
['more-data']. [user].
reconsult('predicates.p').
reconsult(+Files)
[-'more-data.dat'].
Control
predicate examples
abort abort
halt halt.
Terms
predicate examples
| ?- var(X). X = _578 | ?- has_fur(X),
var(?Term)
var(X). no
nonvar(?Term) | ?- nonvar(X). no
| ?-
functor(?Term, ?Name, ?Arity) functor(is_soft(bunny),Name,Arity).
Name = is_soft Arity = 1
| ?- length([green,eggs,and,ham],L).
length(?List, ?Length)
L=4
| ?- name(cat,AsciiList). AsciiList =
name(?Atom, ?Chars)
[99,97,116]
Input/Output
predicate examples
| ?- read(X). % user types,
e.g., has_fur(bunny). X =
read(-Term) has_fur(bunny) Note
input term must be a
valid Prolog term.
| ?- write(cat). cat yes | ?-
write(?Term) write("cat"). [99,97,116]
yes