Atoms and variable examples:
Upper case letters: A,B,…,Z
Lower case letters: a,b,…,z
Digits: 0,1,…,9
Special characters: +,-,<,>,/,*,=,:,.,_,~
Atoms can be constructed in three ways:
String of letters,digits and the underscore character starting with a lower case letter:
anna
x25
x_
x__y
Strings of special characters:
…
.:.
::=
String of characters enclosed in single quotes:
‘Tom’
‘South_America’
‘Sarah Jones’
Numbers used in Prolog include integer numbers and real numbers.
1
-97
-0.035
Using real numbers may cause numerical errors due to rounding, because of this they are not used very often.
Error example in real numbers:
sum(X,Y,Z):-Z is X+Y.
?- sum(2,0.3,C).
C = 2.3 ;
No
?- sum(200,0.0003,C).
C = 200.0 ;
No
The evaluation of the expression “10000+0.0001-10000 “ may result in 0 instead of the correct result 0.0001
Showing posts with label atoms. Show all posts
Showing posts with label atoms. Show all posts
Sunday, 18 January 2009
First Program
Rules:
In order to work, people must be full and delighted.
work(X) :- delighted(X), full(X).
In order to be full, people must eat something.
full(X) :- ate(X).
In order to be delighted, people must sleep and have fun.
delighted(X) :- slept(X), fun(X).
Facts:
Mustafa ate.
ate(mustafa).
Mustafa slept.
slept(mustafa).
Mustafa had fun.
fun(mustafa).
Query:
Can Mustafa work?
Facts:
eats(fred,oranges).
eats(tony,apple).
eats(john,apple).
Queries:
?- eats(fred,oranges). /* yes
?- eats(john,apple). /*yes
?- eats(mike,apple). /*no
In order to work, people must be full and delighted.
work(X) :- delighted(X), full(X).
In order to be full, people must eat something.
full(X) :- ate(X).
In order to be delighted, people must sleep and have fun.
delighted(X) :- slept(X), fun(X).
Facts:
Mustafa ate.
ate(mustafa).
Mustafa slept.
slept(mustafa).
Mustafa had fun.
fun(mustafa).
Query:
Can Mustafa work?
Facts:
eats(fred,oranges).
eats(tony,apple).
eats(john,apple).
Queries:
?- eats(fred,oranges). /* yes
?- eats(john,apple). /*yes
?- eats(mike,apple). /*no
Atoms
likes(john,mary).
In the above fact john and mary are two atomes.
Atoms are usally made from letters and digits with lowercase characters.
Atoms can also be legally made from symbols. The followings are legal atoms :
atoms
hello
zz42
two_words
====>
'two words'
The followings are not legal atoms :
Hello
4hello
_Hello
two words
two-word
The fact likes(john,mary). say that there is a relation between john and mary. It can be read as either john likes mary or mary likes john.
In the above fact john and mary are two atomes.
Atoms are usally made from letters and digits with lowercase characters.
Atoms can also be legally made from symbols. The followings are legal atoms :
atoms
hello
zz42
two_words
====>
'two words'
The followings are not legal atoms :
Hello
4hello
_Hello
two words
two-word
The fact likes(john,mary). say that there is a relation between john and mary. It can be read as either john likes mary or mary likes john.
Labels:
atoms,
characters,
Problems,
prolog,
words
Subscribe to:
Posts (Atom)