345x Filetype PDF File size 0.09 MB Source: www.inf.ed.ac.uk
Getting started
• We’ll use SICStus Prolog
Logic Programming • Free for UofE students
• Can request through Windows support
Lecture 1: Getting started • Available on all DICE machines
• Tutorials, exams will be based on this version
• Online documentation
http://www.sics.se/isl/sicstuswww/site/index.html
Hello World Hello World
• Prolog is an interactive language. • Prolog is an interactive language.
$ sicstus $ sicstus
?-
Hello World Hello World
• Prolog is an interactive language. • Prolog is an interactive language.
$ sicstusPrompt $ sicstus
?- ?- print(’hello world’).
Hello World Hello World
• Prolog is an interactive language. • Prolog is an interactive language.
$ sicstus Goal $ sicstus
?- print(’hello world’). ?- print(’hello world’).
hello world
yes
Hello World Hello World
• Prolog is an interactive language. • Prolog is an interactive language.
$ sicstus $ sicstus
?- print(’hello world’). ?- print(’hello world’).
Output Output
hello world hello world
yes yes
response
Atoms Variables
• An atom is • A variable is a sequence of alphanumeric
• a sequence of alphanumeric characters characters
• usually starting with lower case letter • usually starting with an uppercase letter
• or, a string enclosed in single quotes • Examples:
• Examples: X Y Z Parent Child Foo
homer marge lisa bart
‘Mr. Burns’ ’Principal Skinner’
Predicates Predicates (2)
• A predicate has the form • Predicates have a name
p(t1,...,tn) • = atom p in p(t1,...,tn)
where p is an atom and t1...tn are terms • and an arity
(For now a term is just an atom or variable) • = number of arguments (n)
• Examples:
• Predicates with same name but different arity
father(homer, bart) are different
mother(marge, bart) • We write foo/1, foo/2, ... to refer to these
different predicates
Facts Facts
A fact is an assertion that a predicate is A fact is an assertion that a predicate is
• • Punctuation is
true: true: important!
father(homer, bart). father(homer, bart).
mother(marge, bart). mother(marge, bart).
• A collection of facts is sometimes called a • A collection of facts is sometimes called a
knowledge base (or database). knowledge base (or database).
no reviews yet
Please Login to review.