next up previous
Next: Scope of a variable Up: No Title Previous: Another Example

Prolog Syntax

A query can be used to determine or decide upon number syntax, so for instance :

Q : integer(12)
A : yes
Q : float(10.2)
A : yes
Q : integer(-7.43)
A : no
Q : number(-2.34)
A : yes
Q : number(5322)
A : yes

Atoms

Constants that start with a lower case letter, followed by zero or more alphanumeric characters, for instance :

donut
can_dance
fortran90

symbolic (sequence of symbolic characters)

++
&&

and those with special meaning in Prolog :

! (exclamation mark)
, (coma)
; (semi-colon)

quotes (any sequence of characters in single quotes)

'Apple'
'Alia'
'&them'

again a query format can be used to deduce atoms

Q : atom(alia)
A : yes
Q : atom(123)
A : no
Q : atomic(123)
A : yes (because is an integer)
Q : atomic('123')
A : yes (because is an atom)

What are the distinctions ?

Variables

alphanumeric sequence of characters (include _), starting with a capital letter or underscore, such as

X
Apple
_name
Failed_student

So a query such as :

Q : var(Apple)
A : yes
Q : nonvar(_name)
A : no
Q : var(ola)
A : no
Q : var('Apple')
A : no (because is an atom)

Variables can be anonymous, denoted by the
_ (underscore alone), and used when a return
value is not needed

for instance,

born(heather,cardiff)
born(ben, prague)


Q : born(_,cardiff)
A : yes

The question being asked is :

Is anybody born in cardiff ?, but I do not care who !

Note : Do not use _2 or _(number) as a variable name, as this is how MacProlog32 uses anonymous variables, and represents them internally.


next up previous
Next: Scope of a variable Up: No Title Previous: Another Example

Omer F Rana
Fri Jan 31 13:13:38 GMT 1997