Книга: Introduction to Microprocessors and Microcontrollers

Prolog

Prolog

Prolog is called a ‘declarative’ language in which the program designer does not need to know exactly what the output will be when starting the design of the program. It was first developed in France in 1972 with a view to its use in the development of artificial intelligence. Prolog stands for PROgramming by LOGic. Other versions were developed, such as DEC10, IC Prolog, which were produced in the UK and other versions from the US (see Figure 10.13).


Figure 10.13 A logic-based language

Prolog is another non-procedural language in that it is not a route to a goal but a set of information and a method from which the result can be deduced. Basically the idea is to feed in some facts and ask the program to produce some conclusions. You will remember the little logic puzzles like ‘Graham is married to Anne, Kirk is the son of Peter and the brother of Matt … Is Kirk the brother of …’ You know the sort of thing – more and more interconnected pieces of information until your head hurts. Just the job for Prolog.

The program includes facts and rules then we can ask questions. Here is a really simple example.

Facts:

coins (franc, france)
coins (centime, france)
coins (dollar, usa)
coins (cent, usa)

Rules:

french(x):–coins (x,france)
american(x):–coins (x,american)

Now we ask some questions:

?french (centime)
answer: Yes
?french (dollar)
answer: No

OK so far, but:

?american (dime)
answer: No

It has no data so it cannot say that dime is correct so it plays safe and says it is incorrect.

Оглавление книги


Генерация: 0.650. Запросов К БД/Cache: 2 / 0
поделиться
Вверх Вниз