Prolog for Dummies

Hello World

Here is how we write the prolog hello world program:

image-20221007171422980

Core Idea

The code idea of the prolog is : relation(object1, object2, ..., objectn), and the objects in here also called atoms. The relation is called predicate, the objects object1, object2, ..., objectn involved in the relation are the arguments, and the number n of the arguments is the arity.

English Predicate Calculus Prolog
If –> :-
Not ~ Not
Or V ;
and ^ ,

List

We can easily define the list just like in Python or somewhere else. The things in the list will be called “element”.

1
2
3
[]
[a] which will be same as .(a, .(b, []))
[a, b, c] which will be same as .(a, .(b, .(c, [])))

We can seperate the list into the head and tail:

1
2
3
[a|[]] which equals to [a]
[a|b] is not a list it will be same as .(a,b)
[a|[b]] which equals to [a, b]

The prolog can cover the characters into the list:

1
2
"abc" = [a, b, c].
true.

Prolog for Dummies
http://xiaos.site/2022/10/02/Prolog-for-Dummies/
Author
Xiao Zhang
Posted on
October 2, 2022
Licensed under